Skip to main content
gamedev.net
🔒 Locked

Destroy vs Delete

Started by Phiro Oct 3, 2002 at 2:21 AM 2 replies 250+ views
Original Post
Phiro
Phiro
Another question I''m not sure why, and in fact the actual cause may be something else entirely, but I have a small memory leak, eats up about 20k/sec. I change one thing, and it goes away. In a render function I have an object of CSurface I''m using to blt a bitmap to the screen. At the end of the function I clean up with: 20k/sec leak: g_pBitmap->Destroy(); With no apparent leak: delete g_pBitmap; Why isn''t Destroy good enough?
Alpha_ProgDes
Alpha_ProgDes
i''m no DD guru but if you created g_pBitmap with the new operator then you should destroy it with the delete operator.
but if it''s a newly created object or pointer to an object it should work fine.

see how it was created, then check back, by then someone should tell you how it was works.

if this was no help so sorry.
just trying to understand it myself
Beginner in Game Development?  Read here. And read here.  
Sneftel
Sneftel
It sounds like g_pBitmap is never getting its reference count decreased to zero. Note that you should NEVER call delete on a pointer to a reference-counted object (unless you are the component API, of course). Objects do not expect to be deleted by anyone other than themselves, so their behavior is undefined. Check to see where else the reference count might be incremented, and make sure that any areas that do decrease it after they''re done.


Don''t listen to me. I''ve had too much coffee.
hammerstein_02
hammerstein_02
What exactly is g_pBitmap ? A ddsurface or a something else? I normally use..

if(ddSurface)
{
ddSurface->Release();
ddSurface = NULL;
}

I know you haven't specified which you are using, 7 or 8. so I am guessing, but I thought you called Release because that function removes it and decrements the reference counter.

Hope this is some help

[edited by - hammerstein_02 on October 3, 2002 3:58:42 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.