Deleting things from memory
We have a problem with our game, we are using windows gdi, and we are using FillRect and the program is clogging up memory, how do we delete the things we used in the program from memory so it doesnt slow down the comp after it is closed, if you would like me to explain more, just post it here, any help is appreciated.
free() in C, delete in C++. Delete actually calls free() anyway.
~CGameProgrammer( );
// C++void main (){ char* string = new char [64]; delete [] string; Bitmap* image = new Bitmap; delete image;} // Cvoid main (){ char* string; Bitmap* image; string = malloc(64); free(string); image = malloc(sizeof Bitmap); free(image);}
~CGameProgrammer( );
~CGameProgrammer( );
Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
Along the same lines if you allocate something you have to free it. malloc/free and new/delete are two such instances, but within the Windows API there are a whole lot more. Generally with windows if you receive a handle from windows then at some point you have to free it with a matching function call, i.e. if you call CreateDC then you need to call DeleteDC when you are done with it.
Keys to success: Ability, ambition and opportunity.
working with the GDI can be very confusing
when you create a Pen, Brush, ... don''t forget to delete it with DeleteObject()
and when you call SelectObject(), remember that it returns a handle to the object that was previously selected, if you don''t catch that handle, there''s no way to select it back, and it will stay in memory for the duration of your program
for example:
hope this helps...
when you create a Pen, Brush, ... don''t forget to delete it with DeleteObject()
and when you call SelectObject(), remember that it returns a handle to the object that was previously selected, if you don''t catch that handle, there''s no way to select it back, and it will stay in memory for the duration of your program
for example:
HPEN hPen;HPEN hOldPen;CreatePen(PS_SOLID, 1, 0);hOldPen = SelectObject(hPen);//... do drawing hereSelectObject(hOldPen);//don''t delete the pen while it is still selected!DeleteObject(hdc, hPen)
hope this helps...
Is there an equivalent to realloc in C++? Or do you have to use malloc/realloc/free?
My Geekcode: "GCS d s: a14 C++$ P+(++) L+ E-- W+++$ K- w++(+++) O---- M-- Y-- PGP- t X
R- tv+ b++ DI+(+++) D- G e* h!"
Decode my geekcode!
Geekcode.com
Visit our web site:
Asylum Entertainment
My Geekcode: "GCS d s: a14 C++$ P+(++) L+ E-- W+++$ K- w++(+++) O---- M-- Y-- PGP- t X
R- tv+ b++ DI+(+++) D- G e* h!"
Decode my geekcode!
Geekcode.com
Visit our web site:
Asylum Entertainment
My Geekcode: "GCS d s: a14 C++$ P+(++) L+ E-- W+++$ K- w++(+++) O---- M-- Y-- PGP- t XR- tv+ b++ DI+(+++) D- G e* h!"Decode my geekcode!Geekcode.com
Visit our web site:Asylum Entertainment
Visit our web site:Asylum Entertainment
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement