memory leakage?

This is a discussion on memory leakage? within the C++ Programming forums, part of the General Programming Boards category; i have a question regarding memory leakage. i have a attribute defined in the class like this: MyClass* myObject; function1 ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    11

    Question memory leakage?

    i have a question regarding memory leakage.

    i have a attribute defined in the class like this:

    MyClass* myObject;

    function1 is invoked when the application starts, and allocates memory for myObject:

    myObject=new MyClass(1);

    function2 is latter ran, and does the following:

    myObject=new MyClass(2);

    does this lead to memory leakage? do i have to explicitly delete myObject first and then allocate memory for myObject once again? or can i do as i have done? (it is important for me that the object keeps the original name!).


    thank you
    I use BorlandBuilder 5

  2. #2
    S≠ťnior Member
    Join Date
    Jan 2002
    Posts
    982
    >does this lead to memory leakage?

    Sure does.

    >do i have to explicitly delete myObject

    If you're re-assigning the only pointer you have to it, yes.

    >or can i do as i have done?

    Nothing stopping you (unless you run out of memory), but if people see your code they may make fun of you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 12:57 AM
  2. Memory leak prevention methodogies
    By c___newbie in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 11-17-2007, 02:45 AM
  3. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  4. Suggestions on this C style code
    By Joelito in forum C Programming
    Replies: 11
    Last Post: 06-07-2007, 03:22 AM
  5. Question about the Basics of Memory Leakage
    By Shamino in forum C++ Programming
    Replies: 12
    Last Post: 09-26-2005, 09:42 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21