Re: how to find whether it is released or not
Alex,
I typically would assign a pointer to NULL when I delete it and then I can
check with that.
int *myInt = NULL;
....
if(myInt == NULL)
myInt = new int[100];
....
if(myInt != NULL) {
delete myInt[];
myInt = NULL;
}
When something could be deleted from more than one place you can make this
easier by providing a function to "delete" the object or arrays or whatever
and set them to NULL there.
Tom
"Alex" <Alex@discussions.microsoft.com> wrote in message
news:6ADB4007-4A30-48FD-A8E5-200C51422BBA@microsoft.com...
Hi all,
Please find the below code snippet. There, I deleted memory in main()
function as well as destructor of TestPointer. How to find whether that
resource is already deleted or not? Can I achieve it by using smart
pointers...
#include "stdafx.h"
class TestPointer
{
private:
int* m_pInts;
public:
TestPointer():m_pInts(0){}
~TestPointer(){delete[] m_pInts;}
SetPointer(int* ptrInts){m_pInts = ptrInts;}
};
int main(int argc, char* argv[])
{
int* pints = new int[100];
TestPointer obj1, obj2, obj3;
obj1.SetPointer(pints);
obj2.SetPointer(pints);
obj3.SetPointer(pints);
//stmt...1
//........
//........
//stmt...n
delete[] pints;
return 0;
}
Thanks in advance.
--
Thanks & Regards,
Alex.