Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

SDLx::Surface->blit() Memory Leak #191

Closed
kthakore opened this Issue Jul 26, 2011 · 4 comments

Comments

Projects
None yet
1 participant
Owner

kthakore commented Jul 26, 2011

I did some experimenting with blitting Surfaces. I think the main memory leak I've been seeing is coming from the creation of a new SDLx::Rect every time the Rect coordinates are passed as [x, y, h, w]. By comparing 5 different blits, I was able to find out that by declaring the SDLx::Rect once and reusing it you can avoid this particular memory leak. I originally was working with a single background SDLx::Surface ($background) that has a white rectangle drawn on it. I would then blit this image to the SDLx::App ($app) during the Show Handler.

my $rect = SDLx::Rect->new(0,0,200,200);

Tests

{{{
$background->blit($app) = Steady memory utilization
$background->blit($app, [0,0,200,200]) = Steady increase in memory utilization (~20K/second)
$background->blit($app, [0,0,200,200], [0,0,200,200]) = Steady increase in memory utilization (~30K/second)
$background->blit($app, $rect) = Steady memory utilization, dropped 4K after a minute or two
$background->blit($app, $rect) = Steady memory utilization, shallow fluctuation of +/- 4K ever few minutes
}}}

In the attached code, I've commented out 6 test lines (the blit($app) is duplicated for easy reference) at lines 32-34 & 46-48.

I don't have any fancy way of testing the memory utilization, I just watched the Windows Task Manager for Memory changes on perl.exe (and counted seconds in my head...)

I ran this through the SDL Manual's Pong game and saw a drastic decrease of ~1200KB/s down to a fluctuation of +/- 4KB every few minutes.

Owner

kthakore commented Jul 26, 2011

Author: bobross419
Time: 1294549265
Field: comment
Value: Attached Pong 2.0 (as I call it) which uses the workaround in Memory Tester to reduce the memory leak. Initial testing was done right before the SDLx::Text code was added and there appears to be a minor memory leak occurring from that code whenever the score is updated.

Owner

kthakore commented Jul 26, 2011

Author: froggs
Time: 1296389146
Field: status
Value: closed

@ghost ghost assigned kthakore Jul 26, 2011

Owner

kthakore commented Jul 26, 2011

Author: froggs
Time: 1296389146
Field: resolution
Value: fixed

Owner

kthakore commented Jul 26, 2011

Author: froggs
Time: 1296389146
Field: comment
Value: Fixed here: 30f4412

@kthakore kthakore closed this Jul 26, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment