Jump to content
  • Advertisement
Sign in to follow this  
POLSKASH

Memory Management Help

This topic is 4888 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

I'm having a nasty problem with memory leaks. When my game runs, it pull up the titlescreen, with its background and little icon graphic. Anyways, I select one player, it pulls up the one player game and right now it's taking up 17k memory. Then when I hit escape to go back to the title screen and hit one player again, it's now running at 28k memory! I'm using delete on all the memory that I allocate with new, and for the textures I call Release(). I do all of this in the class' destructors, which the one player and title screens are. Here's are the constructor and destructor of both classes, no other memory is allocated with new anywhere else in each class.
TitleScreen::TitleScreen(IDirect3D9* d3d, IDirect3DDevice9* device, IDirectInput8* dInput8, IDirectInputDevice8* inputDevice, int* purp)
{
	isPlaying = true;
	purpose = purp;
	D3D = d3d;
	D3D_device = device;
	input8 = dInput8;
	keyboard = inputDevice;
	movement_timer = 0;
	
	currentSelection = ONE_PLAYER;
	
	srcRectBg = new RECT;
	srcRectBg->left = 0;
	srcRectBg->top = 0;
	srcRectBg->right = 640;
	srcRectBg->bottom = 480;

	x_icon = 190;
	y_icon = 280;

	srcRectIcon = new RECT;
	srcRectIcon->left = 0;
	srcRectIcon->top = 0;
	srcRectIcon->right = 32;
	srcRectIcon->bottom = 20;
	
	if(FAILED(D3DXCreateSprite(D3D_device, &sprite)))
	{
		MessageBox(NULL, "Failed to create D3DX Sprite Interface!", "Error!",
        MB_ICONEXCLAMATION | MB_OK);
	}

	bg = loadTexture("Debug\\bg.bmp",0xFFFF00FF);
	icon = loadTexture("Debug\\choiceIcon.bmp",0xFFFF00FF);
}


TitleScreen::~TitleScreen()
{
	if(*purpose == -1)//Exiting entire game
	{
		keyboard->Release();
		input8->Release();

		bg->Release();
		sprite->Release();

		D3D_device->Release();
		D3D->Release();

		delete srcRectBg;
		delete srcRectIcon;
	}
	else//Exiting just title screen to pull up another game state
	{
		bg->Release();
		sprite->Release();
		delete srcRectBg;
		delete srcRectIcon;
	}
}

OnePlayer::OnePlayer(IDirect3D9* d3d, IDirect3DDevice9* device, IDirectInput8* dInput8, IDirectInputDevice8* inputDevice, int* purp)
{
	isPlaying = true;
	purpose = purp;
	D3D = d3d;
	D3D_device = device;
	input8 = dInput8;
	keyboard = inputDevice;
	movement_timer = 0;
	
	srcRectBg = new RECT;
	srcRectBg->left = 0;
	srcRectBg->top = 0;
	srcRectBg->right = 640;
	srcRectBg->bottom = 480;

	if(FAILED(D3DXCreateSprite(D3D_device, &sprite)))
	{
		MessageBox(NULL, "Failed to create D3DX Sprite Interface!", "Error!",
        MB_ICONEXCLAMATION | MB_OK);
	}

	bg = loadTexture("Debug\\bgOnePlayer.bmp",0xFFFF00FF);
	//bg = loadTexture("bgOnePlayer.bmp",0xFFFF00FF);

	humanPaddle = new Paddle(D3D, D3D_device, sprite, 1);
	compPaddle = new Paddle(D3D, D3D_device, sprite, 2);

	ball = new Ball(D3D, D3D_device, sprite);
}

OnePlayer::~OnePlayer()
{
	bg->Release();
	sprite->Release();
	delete ball;
	delete humanPaddle;
	delete compPaddle;
	delete srcRectBg;
}

Share this post


Link to post
Share on other sites
Advertisement
Where did you get these numbers from? If you get them from Task Manager, stop worrying. As pointed out elsewhere on gamedev, most OSs do a lot of funky memory work which make these numbers nonsensical for developers most of the time. Rely on memory leak tracing at debug time instead.

Greetz,

Illco

Share this post


Link to post
Share on other sites
Are you checking both the allocated RAM and the virtual memory?
Otherwise, you should re-check your numbers - Windows can, at any given moment, transfer data from RAM to virtual and vice versa to save space for other programs and what not.
Dynamically loaded files could also be the factor (DLL's doesn't have to be loaded at startup).
And finally, as already pointed out, you shouldn't rely too much on Task Manager, since it's not very accurate in all measurements.

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!