Memory Usage and Garbage Collection?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
LuaCre
Prole
Posts: 27
Joined: Mon Dec 03, 2018 11:21 am

Memory Usage and Garbage Collection?

Post by LuaCre »

I have a 2D game Im working on, nothing too major
Has a player, the player can move

Has map generation, 10x10 maps on a 1200x800 screen ,

Has display control for switching maps

Has collidable objects in the map generation, with functioning collision

Press H to switch Maps
Press J to show / hide Hitboxes

Fairly small, only uses the HC library , only 400 or so lines
My problem lies in my memory usage
I notice at some point it goes up by 0.5Mb a second without ever seeming to go down
Ive tried various methods of garbage collection, just experimentation,
All ive noticed are some slight improvements in the initial startup,
but that 0.5mb keeps ticking up,
I havent let it run until it crashes because for it to use 1 gig would take 33 minutes, and having a beefy computer I dont have that time to see
if it will eventually cut down, but when that steady increase starts at 60Mb of usage,
If it doesnt cut down or decrease by 800, I dont think its gonna happen.

So can anybody help me ? Why does the memory usage keep going up by 0.5 Mbs a second.
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Memory Usage and Garbage Collection?

Post by pgimeno »

Hello, welcome to the forums.

To determine whether it's garbage collection failing to run, you can place 'collectgarbage("collect")' in love.update, and see if that keeps memory usage low.

If that doesn't help, then it's most likely either a leak on your side, or you're using a version of LÖVE that has a leak in a function you use. What's your version of LÖVE?

If it helps, then it's likely that the memory usage will stabilize at some point. You need to diagnose this by letting it run all the way until it either stabilizes or crashes. I've had this problem in T2R and I had to manually call collectgarbage in the main loop, to help keep memory usage stable; the origin of the problem was a function that takes a snapshot of a canvas (Canvas:newImageData).
LuaCre
Prole
Posts: 27
Joined: Mon Dec 03, 2018 11:21 am

Re: Memory Usage and Garbage Collection?

Post by LuaCre »

I installed the latest version of love, so its likely on my end, how do I write my code for safe garbage collection?

Also, I did let it run until it indeed crashed, with garbage collection in love.update ,
So I know its a leak on my end
But I dont know how to find where it would be
What it looks like when Im making one
How to write code where I can have tables and arrays that wont make them
Etc, thanks if you can help
Attachments
TopDown.love
Gamefile so maybe you can see what I mean better
(64.91 KiB) Downloaded 140 times
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Memory Usage and Garbage Collection?

Post by zorg »

Yep, pretty unusual, this:
graph.png
graph.png (13.51 KiB) Viewed 5268 times
I looked into it, commented out the Hboxes table insertion lines, and what a suprise, memory consumption rose no more; and cpu utilization was also drastically reduced.
graph2.png
graph2.png (11.42 KiB) Viewed 5268 times
I'd double check what you're doing there if i were you. :3
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
LuaCre
Prole
Posts: 27
Joined: Mon Dec 03, 2018 11:21 am

Re: Memory Usage and Garbage Collection?

Post by LuaCre »

I cant find any solid tutorials with it, I appreciate you finding where the problem is at , saves me loads of trouble, but where would I figure out a proper way to debug the HC implementation?
LuaCre
Prole
Posts: 27
Joined: Mon Dec 03, 2018 11:21 am

Re: Memory Usage and Garbage Collection?

Post by LuaCre »

Well, you were correct, I changed the display and in the process actually made it simpler, and now it seems to even itself out with the garbage collection cycle. Thank you
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Memory Usage and Garbage Collection?

Post by pgimeno »

Thanks for providing the .love file. What you were leaking was HC rectangles, which get registered within HC and not freed unless you remove them.

By changing this line:

Code: Select all

    Hboxes = {}
to this code:

Code: Select all

    for i = 1, #Hboxes do 
        HC.remove(Hboxes[i])
    end
    Hboxes = {}
the leak stopped.

I know you already solved it in some other way, but hopefully this will help you avoid other leaks in future.
Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 34 guests