Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Object Deconstructors

This topic is 6926 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

OK heres the problem. I have a program that uses the new and delete operators to add objects to a CObList. However, ever time i run the program, I lose about 2% of system resources. Memory Leaks. But then, when I was thinking about, doesn't the CObList deconstructor release all the pointers in the list and their associated memory? I don't remember reading any docs that say to manual call delete on each pointer in the list. Any thoughts? OH, and i only use new and delete in my program when im adding things to the CObList, just to refine that that's where the memory leaks are occuring. Edited by - Zipster on 5/8/00 4:09:31 PM

Share this post

Link to post
Share on other sites
Say I have a class CFoo and a variable:
CFoo myFoo;

When I do this:
delete myFoo;

the application is going to execute:

Share this post

Link to post
Share on other sites
I think I see what you are getting at. Consider a CObList with an array of Objects. This can be declared four ways:

1) COb myList[MAX_OBS]; (stack allocated array of objects)

2) COb* myList[MAX_OBS]; (stack allocated array of object pointers)

3) COb* myList; (heap allocated array of objects)

4) COb** myList; (heap allocated array of object pointers)

In the first two cases the default CObList destructor will free the memory used by the array elements. The difference is that in the first example, those elements are the actual objects (so they will be freed) but in the second case, those array elements are just pointers, so the pointers will be freed but the objects themselves will remain.

In the 3rd and 4th examples, the case is similar to the first two. The only difference is that you will have to call new[] to create the list initially, so you will have to explicitly call delete[] to free it (make sure you add teh [] to the delete command since you are deleting an array!)

Hope that clears things up!

Check out the GPI project today!

Share this post

Link to post
Share on other sites
Oh, i see, i misunderstood the MSDN documentation:
When a CObArray object is deleted, or when its elements are removed, only the CObject pointers are removed, not the objects they reference.

i thought this meant that they also delete the memeory. Ok, i got it now, thx.

PCMCIA - People Can't Memorize Computer Industry Acronyms
ISDN - It Still Does Nothing
APPLE - Arrogance Produces Profit-Losing Entity
SCSI - System Can't See It
DOS - Defunct Operating System
BASIC - Bill's Attempt to Seize Industry Control
IBM - I Blame Microsoft
DEC - Do Expect Cuts
CD-ROM - Consumer Device, Rendered Obsolete in Months
OS/2 - Obsolete Soon, Too.
WWW - World Wide Wait
MACINTOSH - Most Applications Crash; If Not, The Operating System Hangs

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!