I'm newbie in programming.
I'm wondering release and delete function.
When I allocate memory with new, I should terminate it with delete.
But when I should use release?
What's the difference release and delete...?
If you are looking for definition you will find
#define SAFE_RELEASE(p) { if ( (p) ) { (p)->Release(); (p) = 0; } }
#define SAFE_DELETE(a) if( (a) != NULL ) delete (a); (a) = NULL;
SAFE_DELETE should be used for memory allocated with new
SAFE_RELEASE should be called for com objects (like directx objects) and "under the hood" is doind something like this
if (--ref_cnt==0)
{
delete this;
}
it decrements a reference counter and releases the object if there are no more references to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With