GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2009-06-05 17:31:52

Smarty
Member
Registered: 2008-01-23
Posts: 15

Memory leak in sprite_replace and background_replace when using PNGs

Brief Description:           Multiple use of sprite_replace and background_replace with PNGs leaks memory
GM Versions:                  GM7
References:                    <none>
Example File:                  http://www.forge.dds.nl/files/pngmemleak.zip
Bug Confirmed:               ---
Hardware Dependent:    No

Main Info:

Using multiple calls to background_replace and sprite_replace to replace a background or sprite resource, using PNG image files of different (!) file sizes, causes the game's memory consumption to increase.

Load the example file into Game Maker 7. Hit CTRL+ALT+DEL and bring up the Processes list. Make sure the column Peak Mem Usage is visible and run the game. You will see memory consumption rise gradually.

The issue is most likely related to the routines used to allocate and deallocate memory to process PNG images.

Workarounds:

1. Use Game Maker 6. The leak has been introduced with version 7.
2. Use BMP, GIF or JPG images instead (the issue only applies to PNG images)
3. Use sprite_delete / sprite_add and background_delete / background_add to replace images.

Offline

#2 2009-06-08 17:33:55

paul23
Member
Registered: 2007-10-17
Posts: 110

Re: Memory leak in sprite_replace and background_replace when using PNGs

I can indeed confirm this bug, seems to happen independent of the arguments (apart from the file), and also happens for background_replace_alpha..

Offline

#3 2009-06-08 17:53:21

Smarty
Member
Registered: 2008-01-23
Posts: 15

Re: Memory leak in sprite_replace and background_replace when using PNGs

Good catch. Then I'm guessing it also happens for sprite_replace_alpha.

Offline

#4 2009-06-08 19:03:50

Marchal_Mig12
Member
Registered: 2009-05-21
Posts: 72

Re: Memory leak in sprite_replace and background_replace when using PNGs

Interesting. I will take that in consideration if I need it later on. However I suggest everyone making any game to use an external resources system as well as a simple editor for their game.

Offline

#5 2009-06-09 02:07:50

icuurd12b42
Member
Registered: 2008-12-11
Posts: 303

Re: Memory leak in sprite_replace and background_replace when using PNGs

Does it drop after running for a long time? It could simply be memory fragmentation.

But one thing you will notice, commentout image1's loading and load image 2... The memory climbs but not as fast

Comment out image2 and uncomment image 1 and the memory is somewhat stable after a few seconds; the memory climbs about 8 k evey 20 seconds...

Offline

#6 2009-06-09 05:03:08

paul23
Member
Registered: 2007-10-17
Posts: 110

Re: Memory leak in sprite_replace and background_replace when using PNGs

Well I ran the program for around 15 minutes and it was stilling climbing after that..

Offline

#7 2009-06-10 17:09:04

xot
Administrator
Registered: 2007-08-18
Posts: 1,201

Re: Memory leak in sprite_replace and background_replace when using PNGs

I can report similar results over a longer period of time.


Abusing forum power since 1986.

Offline

#8 2009-06-17 02:25:15

Smarty
Member
Registered: 2008-01-23
Posts: 15

Re: Memory leak in sprite_replace and background_replace when using PNGs

icuurd12b422 wrote:

Does it drop after running for a long time? It could simply be memory fragmentation.

But one thing you will notice, commentout image1's loading and load image 2... The memory climbs but not as fast

Comment out image2 and uncomment image 1 and the memory is somewhat stable after a few seconds; the memory climbs about 8 k evey 20 seconds...

That's why I indicated that PNGs of different file sizes have to be used to reproduce this bug, and why you also have to look at the peak memory use (regular memory consumption fluctuates so much that it's difficult to discern a leak). If you'd replace the image with a copy of itself you'd never notice.

Offline

#9 2009-06-18 00:57:13

icuurd12b42
Member
Registered: 2008-12-11
Posts: 303

Re: Memory leak in sprite_replace and background_replace when using PNGs

Unless the game ran for a week or something, it still leaks by 8 k every 20 second when same replaces same for the small one.... But for the large one it's more obvious. Different size seems to accelerate the leak. PNG of different size does not need to be used, but it helps to see it sooner. That was my observation at least. Sorry if I was not clear.

Offline

#10 2009-07-03 14:33:57

paul23
Member
Registered: 2007-10-17
Posts: 110

Re: Memory leak in sprite_replace and background_replace when using PNGs

Just to state the obvious: this bug has been fixed in the beta.. (I suspect it was due to the preloading, which has been removed).

Offline

#11 2009-07-03 15:42:52

xot
Administrator
Registered: 2007-08-18
Posts: 1,201

Re: Memory leak in sprite_replace and background_replace when using PNGs

Not obvious at all, thanks for checking that out. Confirmation, anyone?


Abusing forum power since 1986.

Offline

#12 2010-02-03 02:12:51

PlasticineGuy
Member
Registered: 2009-12-12
Posts: 4

Re: Memory leak in sprite_replace and background_replace when using PNGs

No, it still leaks.

Offline

#13 2010-02-03 10:29:53

xot
Administrator
Registered: 2007-08-18
Posts: 1,201

Re: Memory leak in sprite_replace and background_replace when using PNGs

Great. Another "fixed" bug that has reappeared in the release version. WTF, YoYo? Get your act together.


Abusing forum power since 1986.

Offline

Board footer

Powered by FluxBB