Click here to Skip to main content
15,913,709 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: operator new with function free() Pin
xcavin6-Jul-04 1:19
xcavin6-Jul-04 1:19 
GeneralRe: operator new with function free() Pin
Antony M Kancidrowski6-Jul-04 3:34
Antony M Kancidrowski6-Jul-04 3:34 
QuestionQuestion about quering INF file keys? Pin
Behzad Ebrahimi6-Jul-04 0:46
Behzad Ebrahimi6-Jul-04 0:46 
GeneralAccessing a variable from another class Pin
sugumar6-Jul-04 0:43
sugumar6-Jul-04 0:43 
GeneralRe: Accessing a variable from another class Pin
Michael P Butler6-Jul-04 1:04
Michael P Butler6-Jul-04 1:04 
GeneralRe: Accessing a variable from another class Pin
sugumar6-Jul-04 1:20
sugumar6-Jul-04 1:20 
GeneralRe: delete and free Pin
#realJSOP6-Jul-04 0:13
professional#realJSOP6-Jul-04 0:13 
GeneralRe: delete and free Pin
Roger Stoltz6-Jul-04 0:56
Roger Stoltz6-Jul-04 0:56 
As you might know 'new' and 'delete' are C++ keywords for memory allocation and deallocation.
But these small words do more than just memory management.
'new' will call the constructor for the object being created and 'delete' will call the destructor for the object being destroyed. This means that if you create a dynamic object with 'new' and free the memory for that object using 'free', your destructor will not get called and resources allocated by your object will not be freed.
Technically I suppose you could use 'free' given that your class doesn't have to free up any memory in its destructor, but then you have another problem.
When building for Debug some extra bytes will get allocated using 'new' to be able to discover memory leaks and so forth. If you don't use 'delete' at least this memory checking won't work and there is a great risk that the application will crash.

In short:
ALWAYS use 'delete' when you have allocated memory using 'new'.
Using 'free' when deallocating memory allocated using 'new' might work under VERY special circumstances but trying to use this technique would be begging for problems in my opinion.

--
Roger

GeneralRe: delete and free Pin
xcavin6-Jul-04 1:25
xcavin6-Jul-04 1:25 
GeneralHelp from VB programmers Pin
#realJSOP5-Jul-04 23:34
professional#realJSOP5-Jul-04 23:34 
GeneralRe: Help from VB programmers Pin
Duncan Edwards Jones6-Jul-04 0:15
professionalDuncan Edwards Jones6-Jul-04 0:15 
GeneralRe: Help from VB programmers Pin
#realJSOP6-Jul-04 0:56
professional#realJSOP6-Jul-04 0:56 
GeneralRe: Help from VB programmers Pin
Duncan Edwards Jones6-Jul-04 1:47
professionalDuncan Edwards Jones6-Jul-04 1:47 
GeneralRe: Help from VB programmers Pin
anonymous20056-Jul-04 0:53
anonymous20056-Jul-04 0:53 
GeneralRe: Help from VB programmers Pin
#realJSOP6-Jul-04 1:20
professional#realJSOP6-Jul-04 1:20 
GeneralRe: Help from VB programmers Pin
anonymous20056-Jul-04 1:41
anonymous20056-Jul-04 1:41 
GeneralRe: Help from VB programmers Pin
Michael P Butler6-Jul-04 1:29
Michael P Butler6-Jul-04 1:29 
GeneralRe: Help from VB programmers Pin
#realJSOP6-Jul-04 2:14
professional#realJSOP6-Jul-04 2:14 
GeneralRe: Help from VB programmers Pin
#realJSOP6-Jul-04 2:54
professional#realJSOP6-Jul-04 2:54 
GeneralRe: Help from VB programmers Pin
Michael P Butler6-Jul-04 3:57
Michael P Butler6-Jul-04 3:57 
GeneralRe: Help from VB programmers Pin
#realJSOP6-Jul-04 4:53
professional#realJSOP6-Jul-04 4:53 
GeneralRe: Help from VB programmers Pin
#realJSOP6-Jul-04 6:40
professional#realJSOP6-Jul-04 6:40 
GeneralRe: Help from VB programmers Pin
Michael P Butler6-Jul-04 8:31
Michael P Butler6-Jul-04 8:31 
GeneralRe: Help from VB programmers Pin
#realJSOP6-Jul-04 8:48
professional#realJSOP6-Jul-04 8:48 
GeneralRe: Help from VB programmers Pin
Michael P Butler6-Jul-04 9:03
Michael P Butler6-Jul-04 9:03 

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.