Sign in to follow this  
Shorty421

[SDL.Net] Crazy memory leak

Recommended Posts

Shorty421    104
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:

[code]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
}[/code]

'sceneSurface = new Surface(bmp);' is the line which is causing the leak. I have tried putting
[code]sceneSurface.Dispose();[/code]
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: [url="http://pastebin.com/3We9UdVz"]http://pastebin.com/3We9UdVz[/url] is the file which contains the problem
EDIT2: Solved by taking a different approach to rendering.

Share this post


Link to post
Share on other sites
BeerNutts    4400
[quote name='Shorty421' timestamp='1331793548' post='4922184']
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:

[code]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
}[/code]

'sceneSurface = new Surface(bmp);' is the line which is causing the leak. I have tried putting
[code]sceneSurface.Dispose();[/code]
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: [url="http://pastebin.com/3We9UdVz"]http://pastebin.com/3We9UdVz[/url] is the file which contains the problem
EDIT2: Solved by taking a different approach to rendering.
[/quote]

If you new, you must delete

did you try deleting the old scene before you created a new one? ie:
[code]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
}[/code]

Share this post


Link to post
Share on other sites
DoctorGlow    1807
[quote name='BeerNutts' timestamp='1331844172' post='4922390']
[quote name='Shorty421' timestamp='1331793548' post='4922184']
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:

[code]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
}[/code]

'sceneSurface = new Surface(bmp);' is the line which is causing the leak. I have tried putting
[code]sceneSurface.Dispose();[/code]
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: [url="http://pastebin.com/3We9UdVz"]http://pastebin.com/3We9UdVz[/url] is the file which contains the problem
EDIT2: Solved by taking a different approach to rendering.
[/quote]

If you new, you must delete

did you try deleting the old scene before you created a new one? ie:
[code]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
}[/code]
[/quote]

His code is C# not C++

Share this post


Link to post
Share on other sites
Topiary    147
OMG For crazy memory leak - deleaker, valgrind, memcheck.... [img]http://public.gamedev.net//public/style_emoticons/default/cool.png[/img]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this