Finding a Memory Leakage

BlitzMax Forums/BlitzMax Programming/Finding a Memory Leakage

AvestheFox(Posted 2011) [#1]
The longer I play my game the slower it seems to get. (Or it may be the size of the current map and how I'm using certain objects.)

All I know is that I have a memory leak somewhere.

My question here is... what are some of the best methods for finding the potential leakage point?

I'm sure there are some practical methods out there other than sending the entire code to a stranger. :P


H&K(Posted 2011) [#2]
Do you use banks?
Do you stick things on lists,and then forget about them?


AvestheFox(Posted 2011) [#3]
@H&K

I've used banks only once and that's to read tile obstacle types from a file and apply them to the tiles upon map setup. Should I probably use banks for other purposes?

As for forgetting things on lists. Could you be a bit more specific? I'm not sure if I'm being a bit w reckless with my list or not. every tile (foreground and background layers), and entity are stored in a list developed specifically for their own Type and that's the only thing I've ever used list for.


GfK(Posted 2011) [#4]
Don't know if this still applies but you used to be able to use an Int for an image handle (rather than a TImage), but garbage collection never cleaned up in those cases. Don't know if Blitzmax still allows it but that has/did have potential to cause a huge leak.

Also keep an eye on your list counts.


Brucey(Posted 2011) [#5]
you used to be able to use an Int for an image handle

Not if you use Strict or SuperStrict, which I expect AvestheFox does, since he's a good BlitzMax citizen :-)


Jesse(Posted 2011) [#6]
a game getting slower doesn't necessarily means a memory leak. It can also mean an excessive use of the garbage collector; A sign of poor object/memory management.

what kind of game is it?

Last edited 2011


AvestheFox(Posted 2011) [#7]
@Jesse

Its a platform Metroidvania style game. erm.. the early workings of one anyway...

I'll admit, even after a decade of using Blitz related software, I'm still a complete noob when it comes to coding.

My global variables list is quiet massive if that says anything... :P


Yasha(Posted 2011) [#8]
....a game getting slower doesn't usually mean a memory leak, it means the game is doing more (which admittedly may be caused by a memory leak).

The game steadily eating more memory means a memory leak. Have you checked to see how much is actually being used?

Should I probably use banks for other purposes?


...not to avoid memory leaks, no. (They're a relic of old-style Blitz programming; they don't offer anything you can't do otherwise, except for untyped and unsafe data storage, yay!)

Anyway, are you familiar with the circular reference problem? If not, that's one place to start looking.

Last edited 2011


AvestheFox(Posted 2011) [#9]
circular reference problem? cant say I am.

please fill me in :P


AvestheFox(Posted 2011) [#10]
Anyway, I've narrowed the slowdown problem down to a single map in my game. I'm wondering if it has something to do with the size of the map.

the bigger the map the more tiles that are being drawn and on three layers to top it off...

I've already programmed the game to eliminate empty tiles so I'm not sure if its that or not. :P


Jesse(Posted 2011) [#11]
do a millisecs check to see how long it takes to draw the map.

are you drawing tiles off screen also?


My global variables list is quiet massive if that says anything... :P


ouch! management of global variables is really awful. Thats why I love OOP makes management of variables a lot, a lot, a lot... easier.

Last edited 2011


Czar Flavius(Posted 2011) [#12]
I was having memory leaks in my program due to circular references. I don't know if it's the same problem here or not, but I tested it as follows. Have a global variable set to 0, in the new method increase this by 1 and in the delete method decrease this by 1. Then output the number and see if it stays sensible. Quit the level (but not game) entirely and then reload, to see if the numbers have reset.

Make the boundries for clipping tiles smaller than your screen size, to double check it is clipping tiles correctly.

Last edited 2011


ima747(Posted 2011) [#13]
Trust your instincts... a couple things specifically to consider.
How many tiles are you drawing (multiply by layers as needed etc.)
How long are you loops? If you're storing tiles in a tlist, and the map is big, looping through that whole list could take a long time...
Are you doing things you don't need to be (like drawing things that aren't even partially on screen...)
How big/how many images are you using? Are you updating any images regularly? It's quite possible to exceed the vram capacity which means every time you try to draw something that's not loaded on the graphics card it has to first make room on the card by dropping something, then upload the picture you want from RAM, repeat when you want to draw the thing it dropped, etc... every time you edit the pixmap for an image it also (automatically) re-uploads it to the graphics card on it's next draw call... you may not be using a lot of RAM, but you might be thrashing the hell out of the pipe between RAM and VRAM, this causes some CRAZY slowdown, and gets worse with every step over that line you take... and if this is the case, before you have to ask, no, there is no reliable way to get the VRAM limit, it's been a thorn in my side for years now...


AvestheFox(Posted 2011) [#14]
well hey. now there's something... o.o

I thought I had my clipping code in place but apparently I didnt

applying it now to see if it makes a difference!


AvestheFox(Posted 2011) [#15]
HUUUUGE DIFFERENCE!!!

yay. :3

Thanks guys!