Why is easy save using static methods and how to clear memory

Discussion and help for Easy Save 3
Post Reply
Dralks
Posts: 3
Joined: Fri Apr 15, 2022 6:06 pm

Why is easy save using static methods and how to clear memory

Post by Dralks »

Recently we started working on the console ports, we found out that in PC everything works perfectly but consoles were breaking, eventually everything seems to indicate that the issue are our static method, Unity seems to load anything associated with static methods in memory and never let it go (I tried every single cleaning approach suggested, and Unity seems to confirm that it is by design), which increases the memory in every scene, crashing consoles, I proceeded to remove all our static methods but I can see that EasySave uses tons of it, and in the profiler I can see that this approach keeps a lot of things in memory between scenes.

- Why is EasySave using statics if it's known that Unity has memory issues with it?
- How do I clear everything that easy save is loading in memory out of it's static methods?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Why is easy save using static methods and how to clear memory

Post by Joel »

Hi there, and thanks for getting in contact.

We’ve never heard anything like this regarding static methods and don’t appear to be able to find any information on it regarding it and Unity. Static methods are extremely common and even much of Unity’s API uses static methods (including their storage APIs).

Use of static methods shouldn’t be linked to memory usage because they’re two entirely separate mechanisms. Memory is allocated in the same way from a static method as it is from a non-static method. I would be extremely surprised if what you’ve described is the case as this would go against the purpose of garbage collection in object oriented programming. In general static methods are more performant as they don’t require an object to be allocated in memory to be able to call it, and this is consistent with what we’ve seen in the profiler for every platform we support.

Please could you show me the information which led you to this conclusion?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Dralks
Posts: 3
Joined: Fri Apr 15, 2022 6:06 pm

Re: Why is easy save using static methods and how to clear memory

Post by Dralks »

Hey Joel, thanks for answering, I was surprise myself and upset about it, as my code did use quite a lot of statics managers and services but Unity does not give any kind of warning, I saw in many places that statics are to blame for my memory issues as those sprites and textures stay in memory with everything related to them, I thought that any static method would produce that issue, but I'm unsure now, my code base is massive as we have been working in this game for 4 years now and it is almost fully finished, so finding exactly what the issue is is being complicate, I would be happy if I could just clear the whole memory between scenes and having each scene loading only what it needs, something so simple and unity is making it impossible so far, if you are so sure that it is not an issue at all let me keep on working on this and if at the end I see that Easy Save is indeed an issue I will drop you another message.

just some mentions that I found with a quick google:

https://forum.unity.com/threads/keep-ge ... ry.670900/
https://forum.unity.com/threads/assets- ... ne.530937/
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Why is easy save using static methods and how to clear memory

Post by Joel »

Hi there,

The threads you link relate to static variables persisting between scenes, not static methods, so does not apply to Easy Save.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Dralks
Posts: 3
Joined: Fri Apr 15, 2022 6:06 pm

Re: Why is easy save using static methods and how to clear memory

Post by Dralks »

Hi Joel, I finally managed to fix all the issues, I have a few of my own but Easy save is definitely being greedy with memory, adding this to 'ES3ReferenceMgrBase' and then destroying the gameobject solved a lot of memory issues between scenes as those static variables are accumulating memory and not letting it go;

Code: Select all

        
        private void OnDestroy()
        {
            _current = null;
            mgrs.Remove(this);
            mgrs = null;
        }
Post Reply