Possible Memory leak at the shop window

Post here if you need help getting started with Daggerfall Unity or just want to clarify a potential bug. Questions about playing or modding classic Daggerfall should be posted to Community.
Post Reply
User avatar
King of Worms
Posts: 4753
Joined: Mon Oct 17, 2016 11:18 pm
Location: Scourg Barrow (CZ)
Contact:

Possible Memory leak at the shop window

Post by King of Worms »

Hi,

this report is with no mods active, DFU 0.14.5, Windows 10.

When you stand in front of shop shelf, open it -> it adds roughly 7mb to the RAM usage.
Close it, open it again - another 7mb is added.

And this goes ad infinity.
So do it 10 times, its 70mb. Repeat it 100 times, its 700mb.. Still the same shop shelf.


I think in un-modded DFU its not a big issue and thus maybe it was overlooked, but it can possibly become a issue on a modded version with HD assets. Or maybe in a longer play sessions.

Is this a known problem? Feature? Bug?

Best regards :)

User avatar
pango
Posts: 3359
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Possible Memory leak at the shop window

Post by pango »

Hi KoW!

Is memory reclaimed if you wait 3 minutes and open/close the shelf again?

Some resources that were released each time you closed UI windows are now only freed if more than 3 minutes have passed since the last release (PR) because it freezes the game for a short time, and often cause an annoying sound "hiccup". Just making sure release is done from time to time is sufficient to keep memory usage in check during normal gameplay.
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
King of Worms
Posts: 4753
Joined: Mon Oct 17, 2016 11:18 pm
Location: Scourg Barrow (CZ)
Contact:

Re: Possible Memory leak at the shop window

Post by King of Worms »

Hi Pango :)

Yes I have noticed the memory purge is happening from time to time, so that must be it.
I think this is ok solution currently. In normal gameplay, this will not be a issue and I remember that
sound hiccup from the past, which was solved by this implementation.

I think same process happens when I open inventory. If I spam open/close I see memory being filled.
But it purges after a while.

So it seems, this is a feature afterall. ;)
Thanks for explanation/confirmation.

User avatar
pango
Posts: 3359
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Possible Memory leak at the shop window

Post by pango »

Hopefully we'll find even better solutions seamlessly cleaning resources in the background. I added a comment about that some time ago, as a reminder
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
numidium3rd
Posts: 187
Joined: Sun Mar 25, 2018 12:34 am
Location: United States

Re: Possible Memory leak at the shop window

Post by numidium3rd »

This post actually got me working on a branch that proactively destroys assets before they become orphaned (i.e. memory leaks). I've made some good progress but there's a ways to go yet.

I had a thought about modding considerations. Even if I were to destroy every asset before it becomes orphaned there still would be no guarantee that all mods would follow this discipline. Currently DFU waits for a few minutes before doing a sweep so it doesn't do it too often. I think if I am able to plug all the leaks that we could make this interval adjustable or even make the sweep optional (with a warning to the user attached, of course).

User avatar
King of Worms
Posts: 4753
Joined: Mon Oct 17, 2016 11:18 pm
Location: Scourg Barrow (CZ)
Contact:

Re: Possible Memory leak at the shop window

Post by King of Worms »

numidium3rd wrote: Sat Jun 17, 2023 7:24 am This post actually got me working on a branch that proactively destroys assets before they become orphaned (i.e. memory leaks). I've made some good progress but there's a ways to go yet.

I had a thought about modding considerations. Even if I were to destroy every asset before it becomes orphaned there still would be no guarantee that all mods would follow this discipline. Currently DFU waits for a few minutes before doing a sweep so it doesn't do it too often. I think if I am able to plug all the leaks that we could make this interval adjustable or even make the sweep optional (with a warning to the user attached, of course).
Hopefully this will be still compatible with my Dynamic paperdoll backgrounds script :lol:
TODBackgrounds.rar
(7.03 KiB) Downloaded 39 times

User avatar
numidium3rd
Posts: 187
Joined: Sun Mar 25, 2018 12:34 am
Location: United States

Re: Possible Memory leak at the shop window

Post by numidium3rd »

Sure, I don't see why not. The changes shouldn't affect mods but I should do some testing before I say for sure.

User avatar
numidium3rd
Posts: 187
Joined: Sun Mar 25, 2018 12:34 am
Location: United States

Re: Possible Memory leak at the shop window

Post by numidium3rd »

I tested my new asset cleaning branch with D.R.E.A.M and found mostly pleasing results. Unity complains at me when I try to call GameObject.Destroy on modded assets so I had to create a wrapper that runs AssetBundle.Contains on them to make sure they're not loaded from a mod file. Turns out that assets in the asset database clean themselves up automatically via garbage collection. Gee, if only new'd up assets were kind enough to do that >_>........

Anyhow, I noticed in my debugging that there are still a handful of minor asset leaks that seem to be coming from D.R.E.A.M code. King of Worms, I traced a new'd up texture back to TODBackgrounds.cs. There's a relatively simple fix - when you set the background texture on line 456 with GetSubTexture, call GameObject.Destroy on that texture in the line preceding that call and that will ensure there's no dangling texture left over.

I'd be happy to take a look at any other existing D.R.E.A.M code to see if there are any leaks I could help plug. I figure since I'm doing it for DFU I might as well do it for its most popular mod. :D
Last edited by numidium3rd on Mon Jul 17, 2023 6:30 am, edited 1 time in total.

User avatar
King of Worms
Posts: 4753
Joined: Mon Oct 17, 2016 11:18 pm
Location: Scourg Barrow (CZ)
Contact:

Re: Possible Memory leak at the shop window

Post by King of Worms »

Hi Numidium :)

Thanks a lot for the time you spent looking at this part of the game & Dream mod. The TOD script is being developed by a friend Zoran from Nexus, I will forward him Your msg and see what he comes with. I really appreciate your offer to look into the script as well. 1st I will ask Zoran, maybe there is a reason why its solved the way currently is - so lets wait for that. He had to do A LOT of juggling around to make the TOD script compatible with other mods, and that max compatibility is crucial to us in some cases.

Lets see, and thank you once again, I will reply here as soon as know more.

PS: This is the only code in Dream, I try to have as little code in there for compatibility reasons. For the same reason, the Backgrounds will be a separate package, so its easy to disable it

Post Reply