|
-
July 4th, 2007, 12:29 PM
#1
How to identify and release dynamic memory
dear friends
my doubts is how can i identify whether a pointer variable(dynamic variable) having allocated memory or not to free.
Because if you free a variable that is already released.
regards
bagavathikumar
-
July 4th, 2007, 12:39 PM
#2
Re: How to identify and release dynamic memory
You can't find out that information.
All you can do is set pointers to 0 after freeing so that a another call to delete/free would not have any effect ( it is allowed to call delete/free on a null pointer ).
But there could be multiple pointers to the same object and then ths approach would not work.
Kurt
-
July 4th, 2007, 01:37 PM
#3
Re: How to identify and release dynamic memory
Thanks for your immediate reply.
I have a class with one Pointer variable. I wrote a method called SetData. It will get the Input from the user. if the value is 0 to 100, it will allocate a memory to pointer variable. So that i want to release the memory in destructor, if it is allocated. How can identify whether a pointer variable contain the allocated memory.
Thanks in advance
Bagavathikumar
-
July 4th, 2007, 01:40 PM
#4
Re: How to identify and release dynamic memory
In that case you only have to initialize that pointer to 0 in the constructor. Then it is alwais safe to delete that pointer in the destructor.
Kurt
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|