Click here to Skip to main content
15,905,420 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Property Pages question Pin
RobJones16-Nov-01 11:12
RobJones16-Nov-01 11:12 
GeneralRe: Property Pages question Pin
RobJones16-Nov-01 11:52
RobJones16-Nov-01 11:52 
GeneralRe: Property Pages question Pin
Bill Wilson16-Nov-01 13:12
Bill Wilson16-Nov-01 13:12 
GeneralRe: Property Pages question Pin
RobJones16-Nov-01 13:15
RobJones16-Nov-01 13:15 
GeneralRAS events Pin
15-Nov-01 4:24
suss15-Nov-01 4:24 
GeneralRe: RAS events Pin
Masaaki Onishi15-Nov-01 17:07
Masaaki Onishi15-Nov-01 17:07 
GeneralOwner drawn button with drop-down menu Pin
Derek Lakin15-Nov-01 3:35
Derek Lakin15-Nov-01 3:35 
QuestionWhen to delete, and when to NULL? Pin
Chambers15-Nov-01 3:33
Chambers15-Nov-01 3:33 
Hi all, I have got a little lost with regards to pointers. I think its quite simple (if you know the answer), basically I have some code like :

void NewPointer()
{
  if (m_pPointer == NULL)
  {
    m_pPointer = new(MyCPointClass)
    if (m_pPointer->NewPoint)
      return;
    else
      delete(m_pPointer);
  }
}


However, the pointer is deleted in this function, and then its deleted elsewhere in my program through a destructor (which is called when i exit the app). If the BOOL function NewPoint returns TRUE every time then everything is OK (my app doesn`t try to delete the same pointer twice). HOWEVER, it does if it returns FALSE. Basically I need to know if a memory leak would occur if I inserted :

m_pPointer = NULL;

instead of actually deleting it in the function? What actually happens to the memory allocated by new in this case? The reason I ask is because, although my program WOULD expel any memory leaks upon exiting the program, I don`t want them building up whilst I am running the damn thing, because in the end I could run out of memory. So, basically, what I need to know is, if I make the m_pPointer = NULL, will a memory leak occur, and why/why not? Thanks again guys for your intuition,

Cheers,
Alan.Smile | :)

"When I left you I was but the learner, now I am the Master" - Darth VaderMad | :mad:
AnswerRe: When to delete, and when to NULL? Pin
Nish Nishant15-Nov-01 3:50
sitebuilderNish Nishant15-Nov-01 3:50 
AnswerRe: When to delete, and when to NULL? Pin
Jon Sagara15-Nov-01 4:53
Jon Sagara15-Nov-01 4:53 
GeneralRe: When to delete, and when to NULL? Pin
Ray Kinsella15-Nov-01 6:02
Ray Kinsella15-Nov-01 6:02 
GeneralRe: When to delete, and when to NULL? Pin
Jon Sagara15-Nov-01 6:46
Jon Sagara15-Nov-01 6:46 
GeneralRe: When to delete, and when to NULL? Pin
Jim A. Johnson15-Nov-01 6:08
Jim A. Johnson15-Nov-01 6:08 
GeneralRe: When to delete, and when to NULL? Pin
Jon Sagara15-Nov-01 6:50
Jon Sagara15-Nov-01 6:50 
GeneralRe: When to delete, and when to NULL? Pin
Michael Dunn15-Nov-01 9:11
sitebuilderMichael Dunn15-Nov-01 9:11 
GeneralRe: When to delete, and when to NULL? Pin
Jon Sagara15-Nov-01 10:58
Jon Sagara15-Nov-01 10:58 
GeneralRe: When to delete, and when to NULL? Pin
Jim A. Johnson15-Nov-01 12:15
Jim A. Johnson15-Nov-01 12:15 
GeneralRe: When to delete, and when to NULL? Pin
Jon Sagara15-Nov-01 12:36
Jon Sagara15-Nov-01 12:36 
GeneralRe: When to delete, and when to NULL? Pin
Tim Smith15-Nov-01 12:54
Tim Smith15-Nov-01 12:54 
GeneralRe: When to delete, and when to NULL? Pin
Colin Urquhart15-Nov-01 15:47
Colin Urquhart15-Nov-01 15:47 
GeneralRe: When to delete, and when to NULL? Pin
Michael Dunn15-Nov-01 19:07
sitebuilderMichael Dunn15-Nov-01 19:07 
GeneralRe: When to delete, and when to NULL? Pin
#realJSOP16-Nov-01 0:50
professional#realJSOP16-Nov-01 0:50 
AnswerRe: When to delete, and when to NULL? Pin
Gert Boddaert15-Nov-01 5:06
Gert Boddaert15-Nov-01 5:06 
AnswerRe: Thankyou All. Pin
Chambers15-Nov-01 9:32
Chambers15-Nov-01 9:32 
QuestionHow can I open default mail client from my app in VC? Pin
Karavaev Denis15-Nov-01 2:07
Karavaev Denis15-Nov-01 2:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.