|
-
May 7th, 2002, 04:12 PM
#1
Thread Starter
Hyperactive Member
Deallocation
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?
Bababooey
Tatatoothy
Mamamonkey
-
May 7th, 2002, 04:27 PM
#2
Monday Morning Lunatic
You should use plain delete (without the brackets), as long as the pointer was allocated with new.
How is the class constructed?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 7th, 2002, 04:38 PM
#3
Thread Starter
Hyperactive Member
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.
Bababooey
Tatatoothy
Mamamonkey
-
May 7th, 2002, 04:41 PM
#4
Monday Morning Lunatic
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).
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 7th, 2002, 09:30 PM
#5
Thread Starter
Hyperactive Member
why do i get memory leaks then?
Bababooey
Tatatoothy
Mamamonkey
-
May 8th, 2002, 11:09 AM
#6
Monday Morning Lunatic
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.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 8th, 2002, 12:04 PM
#7
Thread Starter
Hyperactive Member
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;
Bababooey
Tatatoothy
Mamamonkey
-
May 8th, 2002, 12:17 PM
#8
Monday Morning Lunatic
I'm confused, the MFC docs say:
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.
...nothing is allocated here and I couldn't find the function you're using
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 8th, 2002, 12:52 PM
#9
Thread Starter
Hyperactive Member
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
Bababooey
Tatatoothy
Mamamonkey
-
May 10th, 2002, 05:34 AM
#10
You shouldn't get a memory leak, the property sheet class deletes all property sheet pointers...
How do you know you have the leak?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 10th, 2002, 09:25 AM
#11
Thread Starter
Hyperactive Member
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 ......
Bababooey
Tatatoothy
Mamamonkey
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
|