Use of new & delete 
Author Message
 Use of new & delete

Is there anything special about the way MFC treats new/delete pairing
please?

IE if my code does a new somewhere I assume I **must** do the
corresponding delete as well to release the memory allocated?

Only if you look at a typical MFC wizard generated program yo see a line
like this:

 CMainFrame* pFrame = new CMainFrame;

in InitInstance but no  delete for it.

I assume that MFC knows about this and tidies up?



Thu, 06 Feb 2003 03:00:00 GMT  
 Use of new & delete
MFC does a lot with new and delete to allow it to do things like allocation
tracking and memory leak detection; however, it does nothing to relieve the
responsibility of deallocating (i.e., delete-ing) the memory you allocate
with new.

What you are seeing with the CMainFrame object is a C++ trick, not an MFC
trick. You will also see that the pointer to the new CMainFrame object is
stored in a member variable of the CWinApp-derived class. When the
application shutdown, cleanup code in the CWinApp class deletes this
pointer.

Dave Smith


Quote:
> Is there anything special about the way MFC treats new/delete pairing
> please?

> IE if my code does a new somewhere I assume I **must** do the
> corresponding delete as well to release the memory allocated?

> Only if you look at a typical MFC wizard generated program yo see a line
> like this:

>  CMainFrame* pFrame = new CMainFrame;

> in InitInstance but no  delete for it.

> I assume that MFC knows about this and tidies up?



Thu, 06 Feb 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. error when using delete & new in class

2. Error Using new & delete in class

3. new & delete

4. new&delete in different threads

5. new&delete - DLL with own heap...

6. new & delete on arrays

7. Overloading new & delete

8. new/delete operator & multithread

9. new & delete

10. new&delete in different threads

11. new&delete - DLL with own heap...

12. Memory Allocation and Freeing using New and Delete Operators

 

 
Powered by phpBB® Forum Software