releasing resources allocated for a particular object

S

ssylee

For example, I have a BITMAPINFO* and a BYTE* object to release the
resources. Would the most bulletproof way of doing so involve checking
to see if they are null, then if they are not, invoke a free()
function call on that and make sure that they point to null?
 
N

news.aioe.org

ssylee said:
For example, I have a BITMAPINFO* and a BYTE* object to release the
resources. Would the most bulletproof way of doing so involve checking
to see if they are null, then if they are not, invoke a free()
function call on that and make sure that they point to null?

Hmm... start with "For example"?

If this is C++ typically you would use "delete" and you can pass a null to the
delete operator.

The best practice is to make a certain component responsible for freeing memory
for certain objects. So resetting a freed pointer variable to NULL to safeguard
from possible multiple freeing of memory clearly is not a good programming practice.
 
J

Jianwei Sun

Hello ssylee,
For example, I have a BITMAPINFO* and a BYTE* object to release the
resources. Would the most bulletproof way of doing so involve checking
to see if they are null, then if they are not, invoke a free()
function call on that and make sure that they point to null?

The C++ way is probably that you wrap the resource in the class, and then
release it in the destructor.

free() is more traditional class c way of doing things.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,169
Messages
2,570,920
Members
47,464
Latest member
Bobbylenly

Latest Threads

Top