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.
Memory Usage and Garbage Collection?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Memory Usage and Garbage Collection?
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).
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).
Re: Memory Usage and Garbage Collection?
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
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
- zorg
- Party member
- Posts: 3444
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Memory Usage and Garbage Collection?
Yep, pretty unusual, this:
I'd double check what you're doing there if i were you.
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.I'd double check what you're doing there if i were you.
Me and my stuff True 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.
Re: Memory Usage and Garbage Collection?
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?
Re: Memory Usage and Garbage Collection?
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
Re: Memory Usage and Garbage Collection?
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:
to this code:
the leak stopped.
I know you already solved it in some other way, but hopefully this will help you avoid other leaks in future.
By changing this line:
Code: Select all
Hboxes = {}
Code: Select all
for i = 1, #Hboxes do
HC.remove(Hboxes[i])
end
Hboxes = {}
I know you already solved it in some other way, but hopefully this will help you avoid other leaks in future.
Who is online
Users browsing this forum: Ahrefs [Bot], Majestic-12 [Bot] and 81 guests