Jump to content

  • Log In with Google      Sign In   
  • Create Account


[SDL.Net] Crazy memory leak


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Shorty421   Members   -  Reputation: 104

Like
1Likes
Like

Posted 15 March 2012 - 12:39 AM

Hey guys, I have a program with a crazy memory leak (leaking ~20mb/s).
I've found the problem, but I can't seem to find a working alternative.

Basically, I have some code which runs on every third tick:

void Draw()
{
  scenebmp.render(bmp, false); //render the current scene to a bitmap image
  sceneSurface = new Surface(bmp); //create a new surface from updated bitmap image
  window.BlitToScreen(sceneSurface); //send the new surface to the 'window' class to be blitted to the screen
}

'sceneSurface = new Surface(bmp);' is the line which is causing the leak. I have tried putting
sceneSurface.Dispose();
at the end of the code block, but it doesn't seem to have any effect.

What would be the best way to fix this?
Is there a way to update the Surface from a bitmap without creating a new Surface?

Thanks for any assistance.

EDIT: http://pastebin.com/3We9UdVz is the file which contains the problem
EDIT2: Solved by taking a different approach to rendering.

Sponsor:

#2 BeerNutts   Crossbones+   -  Reputation: 2765

Like
0Likes
Like

Posted 15 March 2012 - 02:42 PM

Hey guys, I have a program with a crazy memory leak (leaking ~20mb/s).
I've found the problem, but I can't seem to find a working alternative.

Basically, I have some code which runs on every third tick:

void Draw()
{
  scenebmp.render(bmp, false); //render the current scene to a bitmap image
  sceneSurface = new Surface(bmp); //create a new surface from updated bitmap image
  window.BlitToScreen(sceneSurface); //send the new surface to the 'window' class to be blitted to the screen
}

'sceneSurface = new Surface(bmp);' is the line which is causing the leak. I have tried putting
sceneSurface.Dispose();
at the end of the code block, but it doesn't seem to have any effect.

What would be the best way to fix this?
Is there a way to update the Surface from a bitmap without creating a new Surface?

Thanks for any assistance.

EDIT: http://pastebin.com/3We9UdVz is the file which contains the problem
EDIT2: Solved by taking a different approach to rendering.


If you new, you must delete

did you try deleting the old scene before you created a new one? ie:
void Draw()
{
  scenebmp.render(bmp, false); //render the current scene to a bitmap image
  if (sceneSurface) {
    delete sceneSurface;
  }
  sceneSurface = new Surface(bmp); //create a new surface from updated bitmap image
  window.BlitToScreen(sceneSurface); //send the new surface to the 'window' class to be blitted to the screen
}

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#3 DoctorGlow   Members   -  Reputation: 766

Like
1Likes
Like

Posted 15 March 2012 - 02:58 PM


Hey guys, I have a program with a crazy memory leak (leaking ~20mb/s).
I've found the problem, but I can't seem to find a working alternative.

Basically, I have some code which runs on every third tick:

void Draw()
{
  scenebmp.render(bmp, false); //render the current scene to a bitmap image
  sceneSurface = new Surface(bmp); //create a new surface from updated bitmap image
  window.BlitToScreen(sceneSurface); //send the new surface to the 'window' class to be blitted to the screen
}

'sceneSurface = new Surface(bmp);' is the line which is causing the leak. I have tried putting
sceneSurface.Dispose();
at the end of the code block, but it doesn't seem to have any effect.

What would be the best way to fix this?
Is there a way to update the Surface from a bitmap without creating a new Surface?

Thanks for any assistance.

EDIT: http://pastebin.com/3We9UdVz is the file which contains the problem
EDIT2: Solved by taking a different approach to rendering.


If you new, you must delete

did you try deleting the old scene before you created a new one? ie:
void Draw()
{
  scenebmp.render(bmp, false); //render the current scene to a bitmap image
  if (sceneSurface) {
	delete sceneSurface;
  }
  sceneSurface = new Surface(bmp); //create a new surface from updated bitmap image
  window.BlitToScreen(sceneSurface); //send the new surface to the 'window' class to be blitted to the screen
}


His code is C# not C++

#4 Topiary   Members   -  Reputation: 147

Like
0Likes
Like

Posted 11 July 2012 - 01:21 PM

OMG For crazy memory leak - deleaker, valgrind, memcheck.... Posted Image




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS