what's wrong with this code?
CMyClass *pointer = (CMyClass*)SomeThing
...do stuff with pointer
// Done with pointer
delete[] pointer
i get a memory leak without deleting it and i get an access
violation with it
any ideas?
Printable View
what's wrong with this code?
CMyClass *pointer = (CMyClass*)SomeThing
...do stuff with pointer
// Done with pointer
delete[] pointer
i get a memory leak without deleting it and i get an access
violation with it
any ideas?
You should use plain delete (without the brackets), as long as the pointer was allocated with new.
How is the class constructed?
i'm not creating the pointer with new,
the *pointer is of type CMyClass
if you want the exact example....
http://www.codeproject.com/dialog/csettingsdlg.asp
when OK is clicked you need to delete one of the pages
however i'm gettin memory exceptions like i have mentioned.
You can't arbitrarily delete something. If it was automatically allocated (i.e. on the stack) then it'll get sorted out by the compiler.
Surely MFC provides a way to delete a page from a property sheet? (FYI I didn't look at the source since it won't mean anything to me, considering I've been avoiding MFC for a while now).
why do i get memory leaks then?
Do you have the specific bit of code where its allocated? If it's created with new then it must be deleted at some point, once anything that uses the pointer has finished with it.
Code:CPropPageDir *dirPage = (CPropPageDir*) dlg.AddPage(RUNTIME_CLASS(CPropPageDir), "Directories", IDD_PROP_DIR, "Settings");
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// Do some stuff
}
delete[] dirPage;
I'm confused, the MFC docs say:...nothing is allocated here and I couldn't find the function you're using :confused:Quote:
MFC Library Reference
CPropertySheet::AddPageSee Also
CPropertySheet Overview | Class Members | Hierarchy Chart | CPropertySheet::RemovePage
Adds the supplied page with the rightmost tab in the property sheet.
void AddPage(
CPropertyPage *pPage
);
Parameters
pPage
Points to the page to be added to the property sheet. Cannot be NULL.
sorry, i'm not using the standard property pages
i'm using the netscape-like preferences dialog from
http://www.codeproject.com/dialog/csettingsdlg.asp
You shouldn't get a memory leak, the property sheet class deletes all property sheet pointers...
How do you know you have the leak?
in the debug output window, it'll say memory leak detected
and the size of the property sheet
for some reason it's not doing it now ......