Jump to content
  • Advertisement
Sign in to follow this  
AKClaus

Memory Usage Grows & grows(solved)

This topic is 3691 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Im trying to learn C++ and DirectX, i was doing good until i saw in the Process Manager the Memory Grew and Grew, so i tried to fix it, and thanks to my newbiness i cant fix it, altough i think i know where it is: void UpdateScene(void){ d3dinput->poll(); if ( d3dinput->KeyDown( DIK_W ) ) { //So Here is where it leaks cameraobject->x -= ( 10.0f*fpsobject->FPS_delta_time )* cos( cameraobject->direction ); } cameraobject->UpdateViewMatrix(); } I removed a lot of code since this is the main problem ( is the same in all others ), so the leak happens when i substract/add to that variable, doesnt matter if its 1.0 or that code, yet i dont know whats wrong. Here is the Camera class : class Camera { public: Camera(); ~Camera(); void SetWorld(void); void UpdateProjectionMatrix(void); void UpdateViewMatrix(void); float direction, direction_y, x, y, z, tx, ty, tz, vx, vy, vz; D3DXMATRIX world; private: D3DXMATRIX projection, view; }; Thanks for your Help. //EDIT : Corrected The Subject Thx to Zahlman. old & wrong subject( Memory Leak ). [Edited by - AKClaus on July 11, 2008 6:17:23 PM]

Share this post


Link to post
Share on other sites
Advertisement
How did you determine that there is a leak? Does the memory usage continually increase in the process manager?

The line below //So Here is where it leaks just looks like simple math with no memory allocations... maybe the problem is in UpdateViewMatrix?

Share this post


Link to post
Share on other sites
I have a strong feeling that your memory leak is happening somewhere else. Memory leaks occur when you create dynamic memory, i.e. by calling new on a pointer, and forget to call delete. I would suggest going through your code line by line looking for dynamic memory allocation and making sure it is freed.

Share this post


Link to post
Share on other sites
Yes The Memory starts at 11,215 then when i press W it increases and when i release W it stops and stays still until i press again, thats why I saw it was there i also tried removing all the code but the math and the key:

void UpdateScene(void){

d3dinput->poll();

if ( d3dinput->KeyDown( DIK_W ) )
{
/////So Here is where it leaks
cameraobject->x -= ( 10.0f*fpsobject->FPS_delta_time )* cos( cameraobject->direction );
}
/////cameraobject->UpdateViewMatrix();
}

And still happend, I really dont know why it happens, I made it static and still, changed it to :

cameraobject->x -= 1.0f; //This is why i know it happens only when i substract/add.

And still, dont know what else to do, and rewritting it, i dont think itll help, No idea what causeses it.

Share this post


Link to post
Share on other sites
Ok so i found out what it was ( rewritting part by part did help XD ), its far from this, theres nothing wrong with this code ( altough is a very old and newb way, using D3DVECTOR3 is better =P ), so the error was in the DrawScene function, something is wrong when i call the font to drawtext:

void DrawScene(HWND window) {

Check_Failure( d3ddevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 0, 0, 255), 1.0f, 0) );
Check_Failure( d3ddevice->BeginScene() );
{
cameraobject->SetWorld();
basic_cube->Draw();
fpsobject->Draw( 10,10, true, true);

/*/I Removed this and the leak dissapeared:

RECT position={ 10,65, 0,0};
static char buffer[64];
sprintf_s( buffer, sizeof(buffer), "X: %.4f", cameraobject->x );
d3dfont->DrawTextA( NULL, buffer, -1, &position, DT_NOCLIP, D3DCOLOR_XRGB( 255,255,0) );

/*/

}
Check_Failure( d3ddevice->EndScene() );
Check_Failure( d3ddevice->Present(NULL, NULL, NULL, NULL) );

}

This also happend with the ' fpsobject->Draw( 10,10, true, true); '.

If i remove the code:
d3dfont->DrawTextA( NULL, buffer, -1, &position, DT_NOCLIP, D3DCOLOR_XRGB( 255,255,0) );

then it doesnt grow anymore, i dont know why it happens.

Do I have to do something with the buffer before Drawing it ????

Thx For Your Help.

[Edited by - AKClaus on July 10, 2008 6:21:14 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by AKClaus
Yes The Memory starts at 11,215 then when i press W it increases and when i release W it stops and stays still until i press again


If you are looking at this with the Windows Task Manager, that does not mean you have a memory leak.

Share this post


Link to post
Share on other sites
Ok so I did a little more of search and found out that releasing the font and then recreating it freed the memory, giving me a solution to my problem, apparently this is " By Design " and not my fault ( xD gave me a headache last night ).

Anyway Thx and hope it helps.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!