Memory leak on low-end Devices

Hi,

i have been developing a small Bingo game that has to work in a Android TV with at least 24h of continuous runtime.

We managed to make it run at 60 fps no problem, but after a few loops our game just crashes…all the symptons indicate a memory leak, but we cant find this leak in the profiler!

we have just 2 scenes:

1 main game scene, that gets a file from a server/localpath(if offline), and use that file to run the game logic(the balls ordering and any random), it has a few animations, no instantiate, just pooling, no resources call ,no coroutine. we call all the possible GC/resources/cache methods to unload here.

a 2a empty game scene, with just a counter, that also calls every clear method and goes back to scene 1.

i don’t really know what i could do, i went after every single optimization that i could do :stuck_out_tongue:

What do you mean by “just crashes?” Does it freeze? Or does it drop back to the TV launcher?

Either way, definitely start with attaching the USB cable so you can get at adb logcat, either from the command line or else through integration with Unity (google for this).

That way you can tell if there is an exception being thrown, or if there are low memory warnings happening.

If it is just a freeze, check for endless loops in your logic, such as searching for an empty spot to put something and there is no empty spot so it loops endlessly, that sort of thing.

We have been adb’ing 10 different tvs for the past 3 days :frowning:

just freezes, sorry, poor choice of words.

there is no low memory warning and no exception thrown.

it is a 90-count loop…and then it goes for a empty scene that destroys and ends every loop, i already made the game ground-up 3 times trying to find this error :frowning:

If it just freezes it is extremely likely to be an endless loop. Look around your loops and make sure there’s no possible way they can endlessly spin. Feel free to post the logic here for discussion and a second set of eyeballs.

i would really appreciate if you could take a look :stuck_out_tongue:

https://github.com/MgCohen/KenoLight

i cant really post the code here as it has a few scripts…but is a small project, made overnight, we made all possible optimizations we cound imagine

→ no coroutines
→ no events
→ no linq
→ no animation
→ no resources
→ no SO
→ super-optmized sprites

right now i’m converting the whole game from UI to 2D

Bump, Anyone ele can give a Hand? We are running out of options here :stuck_out_tongue:

I doubt you’re going to get anyone to spelunk your code.

Have you tried just running it for 24 hours through the editor? Attach the visual studio debugger when you do it and when you see it “freeze” go into VS and hit pause on the debugger and see where in the code you are.

Cause if it’s some loop/logical issue causing infinite loops… it should happen on any machine regardless of hardware.

1 Like

yep,

on computer it never happens, spend over 48hrs.

there is no infinite loop, i guarantee you. something is leaking memory.

we belive something is randomly not getting cleaned by GC(even though we try to force GC every time we can) and eventually pilling up…

If you really truly believe it’s a memory leak in the memory manager… welp, attach a remote profiler and see what is going on with your memory.

Here’s instructions on how to do that:

Though in my opinion it’s probably not the memory manager itself as that’d be a giant glaring fault in .net or unity’s IL2CPP. But hey, it could be there, they aren’t perfect. And if you prove it to be such… submit a bug report immediately as such a thing would impact pretty much everyone.

But I still doubt it since you say you’re forcing GC. That’d fix pretty much any memory leak in the memory manager. The only way things would get stuck then would be if the ref counter got corrupted OR you held references keeping that ref counter non-zero accidentally (which isn’t the memory manager’s fault).

The more likely… if it’s memory related… is that you have assets not getting cleaned up properly. You may not be properly destroying assets in places. Or leaving hanging references out there. Who knows.

In the same respect… it might not be memory at all.

We here on the forums could only guess without actually spelunking your code and running your project. All we have is your word to go on.

So…

Run the profiler.

See what it says, as it’d likely know better. It’ll give you not only memory information but pretty much everything you’d want to know about what’s going on in your game.

And if you’ve already done this.

OK… show us what the profiler said when it froze.

Oh… I should also point out.

I noticed your game is called “KenoLight”, and you’re saying this must be able to run for 24 hours on an androidtv.

Keno is a gambling game.

Also the context of running on an androidtv sounds like a “game room” setting. I used to do contracting work in the gameroom/gambling industry for a few years and got pretty familiar with it. At the time I looked into developing games for some of my clients using Unity…

Well…

Unity requires a special gambling license if your game will be used for anything it considers gambling:

Figured you should know that, in case you didn’t know. It’d suck if you poured a whole bunch of R&D on something that it turns out the licensing for which doesn’t meet your budgetary requirements. Gambling games tend to have very specific margins that are heavily regulated within their markets. It’s the reason I didn’t end up using Unity as it didn’t meet any of my client’s budgetary requirements. (I won’t even get into local market regulations as that is super complicated and specific to your region… and I hope you, or your client, have already done that research. It’s just the Unity license isn’t as well known about. Also I’m not a lawyer.)

Then again you might be building a Keno game for funsies as a proof of concept to learn/demonstrate a proficiency in Unity. In which case it don’t matter. Everything I said only applies if this Keno game is going to be deployed in a setting where real money will be transacted.

We already used the profiler, thats why i`m appealing to the forums :stuck_out_tongue:

And as I said:

We forum users don’t like shooting in the dark. :stuck_out_tongue:

Otherwise… pay a professional to spelunk your code for you and figure it out.

yep!

we are aware!

however, its not for money, its for a arcade

What kind of “arcade”? Cause uhh, some places refer to game rooms as “arcades”. For example my home state of Florida calls them “Arcades”.

a themed bar, with random games for something free, no money exchanged

go in, get a beer, maybe you get a free beer just for being there

ALSO, just to clarify, its not US based

like I said… those laws get complicated and it’s a cross-section of what Unity considers gambling and your local government considers gambling. It’s not like the US is the only place that gambling is heavily regulated. I merely used Florida because I’m from Florida. I was merely bringing it up so you didn’t waste your time if gambling was the setting. Cause we only know what you tell us… and when I see “Keno” I hear “gambling”.

Regardless, that’s a tangent.

Back at you using the profiler…

so, what did it say???

memory profiler shows there is no difference in memory usage overtime…so if there is a leak, its not getting captured

profiler shows a spike in some frames, but its due to the game itself running(scene load, unload, basic loop)

the game loop has been reduced to basically 60 spriterenderers on screen, each with a sprite of a number…each changing once every frame for 90 frames.

a normal game loop should take around 5 minutes of gameplay, 10 of waiting time(empty scene)

but testing like that would take even more days, so we reduced to a 1 minute gameplay and 5 secondes of waiting, some animations and stuff…this way we achieved at most 200 gameloops(game scene → wait scene → game scene) before freezing

with this reduced gameplay…we reached around 1500…but as soon as i put this reduced thing online, it got back to 70.

there is no warning, there is loop, the second scene is empty and i even go out of my way to check every scene if there is additive/unneeded/repeated scenes loaded.

the moment it freezes is always different…it is…weird :stuck_out_tongue: only happens on low-end devices, probably something with large object stack, but i cant possible find a solution.

PS: sorry if anything is hard to understand, trying my best at english here

See if you can create a memory dump and inspect where it has frozen.

On Windows, you can create a dump file via Task Manager and inspect the stack in Visual Studio. I am sure there is something similar you can do with Android.

You could also try adding Debug.Log statements everywhere throughout your code and seeing what the last printed message is.

I doubt the issue is a memory leak. Apps that eat too much ram are usually terminated by the OS rather than hang.