playMaker

Author Topic: LoadLevel memory leak [SOLVED]  (Read 5550 times)

thefonz

  • Playmaker Newbie
  • *
  • Posts: 24
  • Augmentititus
    • View Profile
LoadLevel memory leak [SOLVED]
« on: March 10, 2016, 02:58:29 AM »
Hi all,

Im running the latest version of playmaker + unity 5.2.1 and building for iPhone 6.
when using LoadLevel to switch through scenes i get memory leaks and the app crashes.

any help with be greatly appreciated.

Thanks
Ahmed
« Last Edit: March 18, 2016, 08:04:55 AM by Alex Chouls »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4613
    • View Profile
    • jinxtergames
Re: LoadLevel memory leak
« Reply #1 on: March 10, 2016, 07:00:06 AM »
Hi,
A bit more info would be helpfull :)

Are you using a stripping level when building your game?
(many times this gives problems before with me. if so try disabling this 1st)

In the load level action do you have Additive and/or Async checked

Are you using don't destroy on load.

Does the load level work when you play in the editor?

thefonz

  • Playmaker Newbie
  • *
  • Posts: 24
  • Augmentititus
    • View Profile
Re: LoadLevel memory leak
« Reply #2 on: March 10, 2016, 10:20:30 AM »
hey djaydino sure thing..

stripping level is disabled.
i've tried it with none and tried it with async....both times = memory leak and im not using dont destroy.

the level switching works fine in the editor, i dont get any crashes or bugs.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14684
  • Official Playmaker Support
    • View Profile
Re: LoadLevel memory leak
« Reply #3 on: March 10, 2016, 11:11:57 AM »
Hi,

If the leak is indeed related to Unity's own level loading system, then

Can you try this:

http://hutonggames.com/playmakerforum/index.php?topic=2200.msg9694#msg9694

else, you'll need to use the Unity profiler and find exactly what is leaking, it could be a texture, or a GameObject that is instantiated and set to "not destroy on load" and thus never released from memory, and as your game is progressing more and more of these are created.

Let me know how it goes,

Bye,

 Jean

thefonz

  • Playmaker Newbie
  • *
  • Posts: 24
  • Augmentititus
    • View Profile
Re: LoadLevel memory leak
« Reply #4 on: March 11, 2016, 02:31:40 AM »
Hi Jean

I tried to use that solution but i couldnt get it to work..could you advise me please on how to go about it?

my scenes:
lvl1=home
lvl2=apartment finder
lvl3=four plex

how would i set it up using your levelcleaner?

thanks
« Last Edit: March 11, 2016, 02:56:44 AM by thefonz »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14684
  • Official Playmaker Support
    • View Profile
Re: LoadLevel memory leak
« Reply #5 on: March 11, 2016, 03:44:41 AM »
Hi,

 the post has some instructions, have you followed them?

Quote
Instructions:

1: add scene_manager to the scenes' build as the first scene
2: add the other scenes (__emptyLevel__ scene_cube and scene_sphere)
3: run on IOS with profiler on with the memory section
4: as you load watch that it doesn't leak

Fair enough the scenes are rather dull :) but the goal is that you try with your scenes and see if it stack up

you will simply replace scene cube and sphere with your own ones basically.

 Let me know how it goes, else can you detail what isn't working as expected.

Bye,

 Jean

thefonz

  • Playmaker Newbie
  • *
  • Posts: 24
  • Augmentititus
    • View Profile
Re: LoadLevel memory leak
« Reply #6 on: March 18, 2016, 02:43:14 AM »
Hi,

I'd just like to update you that i got my scene working fine now, turns out it wasnt as optimized as i thought it was after looking at the unity profiler.

thanks again for all the help guys.

szomaza

  • Sr. Member
  • ****
  • Posts: 253
    • View Profile
Re: LoadLevel memory leak [SOLVED]
« Reply #7 on: December 14, 2016, 01:06:33 PM »
Found this while searching for solutions.

I am experiencing some problems when building for iOS.
1. On a bit older iPad the app works, (does not crash so far ever) but regularly hangs for several seconds. (Maybe when it should be playing a sound or running more FSMs) When it does not hang it is not laggy so it is not a performance issue.
2. On iPhone6 the app works fluently, but at the start of one mini game where I am spawning 100 prefabs, all with several FSMs, the app can crash frequently and xCode only says: "memory issues"

On both iOS devices, when this minigame is loading the memory usage drastically climbs and then never goes back to the initial base level.

I am also using load level action to load in minigames and new lesson content. After each lesson I destroy the whole level, (everything in the level is a child of one object, which I destroy) but the memory usage does not go down. Shouldn't it eventually go down as it is freed up automatically?

I have additive checked in the load level actions, which I think is how it should be as I don't want to overwrite my main scene.

Load Level action
https://hutonggames.fogbugz.com/default.asp?W71
Application.LoadLevelAdditive
https://docs.unity3d.com/ScriptReference/Application.LoadLevelAdditive.html

Any ideas what I should try to figure this out?
Has anybody experienced such anomalies with iOS?

Oh, one more fun thing: the app has been tested and works flawlessly on many different Android devices. It even runs slow but without crashing on low end device.

Thanks in advance for any insights!
szomaza
« Last Edit: December 14, 2016, 01:13:03 PM by szomaza »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14684
  • Official Playmaker Support
    • View Profile
Re: LoadLevel memory leak [SOLVED]
« Reply #8 on: December 15, 2016, 01:23:54 AM »
Hi,

 Can you look at the following and test it:

http://hutonggames.com/playmakerforum/index.php?topic=2200.msg10674#msg10674

 Bye,

 Jean

szomaza

  • Sr. Member
  • ****
  • Posts: 253
    • View Profile
Re: LoadLevel memory leak [SOLVED]
« Reply #9 on: December 17, 2016, 12:44:35 AM »
I am trying this now, but it looks like an ancient solution to the problem.
What about the Load Level Clean action on the Ecosystem?
https://github.com/jeanfabre/PlayMakerCustomActions_U4/blob/master/Assets/PlayMaker%20Custom%20Actions/Application/LoadLevelClean.cs
Isn't that the better version/solution to this problem?

Found it here: http://hutonggames.com/playmakerforum/index.php?topic=11350.msg53515#msg53515

Edit:
I don't get this: Why do you need to load an empty scene to free up the memory from destroyed objects?
Currently I load a scene and when not needed anymore, I destroy everything it has loaded. Shouldn't the memory usage go down after that?

Anyway, in this case:
"at the start of one mini game where I am spawning 100 prefabs, all with several FSMs, the app can crash frequently and xCode only says: "memory issues"
I am not even doing this from a loaded scene, but spawning these from an FSM in my main scene and then destroying each GameObject with their own template FSMs.

Edit2:
Managed to run in xCode and profile your (LoadLevelClean.unitypackage) and it seems to work as expected: the memory usage is not going up as I keep on loading the cube or sphere scenes.
This is good, but I did not have any problem with this.
If I profile my app, and load a bunch of scenes (without using this solution) the memory usage stays stable, does not keep increasing.
Of course it goes up when a scene is loaded, but after destroying it and reloading several times, the memory usage does not go any higher.

My problems are still:
1. On a bit older iPad the app works, (does not crash so far ever) but regularly hangs for several seconds. (Maybe when it should be playing a sound or running more FSMs) When it does not hang it is not laggy so it is not a performance issue.
2. On iPhone6 the app works fluently, but at the start of one mini game where I am spawning 100 prefabs, all with several FSMs, the app can crash frequently and xCode only says: "memory issues"

Any ideas what I could try to figure these out?

Thanks for any help!
szomaza
« Last Edit: December 17, 2016, 01:50:45 AM by szomaza »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14684
  • Official Playmaker Support
    • View Profile
Re: LoadLevel memory leak [SOLVED]
« Reply #10 on: December 19, 2016, 12:34:18 AM »
Hi,

Then that's something with this prefab in particular, what actions are used in this prefab?

Can you profile and see what's going on when instantiating these 100 instances?

Bye,

 Jean

szomaza

  • Sr. Member
  • ****
  • Posts: 253
    • View Profile
Re: LoadLevel memory leak [SOLVED]
« Reply #11 on: December 29, 2016, 07:30:46 AM »
Nothing particularly specific in those prefabs, but trying several different things to try to optimize it... I'll post here if I find out what was the problem.
So far I have modified it so that I put those 100 objects into a separate scene, so I am not creating them from prefabs on the fly when the minigame loads, but loading them in from a scene. This does not seem to help, it still takes a long time to start them up and takes a lot of memory while loading them.

About the clean level load thing (LoadLevelClean.unitypackage).
There is also a "Load Level Clean" action in the Ecosystem, which seems to do the same, just a better implementation as it does not require Send Message-ing.
1. Both load an empty level before the intended one. Why is this required?
2. They don't load the intended level additively. (Everything else that is not marked to Dont Destroy On Load is removed.)

Can this work with additive loading?
Or should I just mark all the game objects in my main scene that I need to keep when loading levels with the "Dont Destroy On Load" action?

Thanks in advance,
szomaza

szomaza

  • Sr. Member
  • ****
  • Posts: 253
    • View Profile
Re: LoadLevel memory leak [SOLVED]
« Reply #12 on: January 07, 2017, 02:25:16 AM »
1. One things solved:

I had a "memory issues" problem and the app crashing at the start of one mini game where I am spawning 100 prefabs, all with several FSMs.

It seems that spawning these objects from prefabs and having them change their color by swapping their mesh object was the reason for abnormally high memory consumption.

I modified it the following way and now the memory consumption is healthy and there are no crashes: now I load in 10 different templates form a scene, then create 9 copies of each to get the 100 pieces and also changed their color change FSM from swapping meshes to material changes.
Not sure at all but I guess the extreme memory consumption might have been because each of the 100 prefabs loaded the 100 different meshes it might have to be able to change to during the game???

2. This problem I still need to figure out:

On a bit older 4th gen iPad the app works, but regularly hangs for several seconds. (Maybe when it should be playing a sound or running more FSMs)
When it does not hang it is not laggy so it is not a performance issue.

Any idea what could be causing this hanging?
Why only on iPad? (happens on 2 out of 2 iPads so far tested)
I don't experience this on iPhone 6, or any Android device, even laggy old ones.

The app is live if anybody has the time to try it out with an iPad to see exactly what I am talking about:
https://itunes.apple.com/app/id1184982624
https://play.google.com/store/apps/details?id=com.Emese.English

3. Please shed some light on this level loading mess I am having:

About the clean level load thing (LoadLevelClean.unitypackage).
There is also a "Load Level Clean" action in the Ecosystem, which seems to do the same, just a better implementation as it does not require Send Message-ing.
1. Both load an empty level before the intended one. Why is this required?
2. They don't load the intended level additively. (Everything else that is not marked to Dont Destroy On Load is removed.)

Can this work with additive loading?
Or should I just mark all the game objects in my main scene that I need to keep when loading levels with the "Dont Destroy On Load" action?

Thanks in advance,
szomaza

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14684
  • Official Playmaker Support
    • View Profile
Re: LoadLevel memory leak [SOLVED]
« Reply #13 on: January 09, 2017, 12:39:52 AM »
Hi,

 3: yes, the empty scene is the key to proper clean up.

try the one on the ecosystem it if it works then use it. It is more recent than the package yes.

indeed it's not meant for additive loading, because then you can't force cleanup, which is the reason for this setup. Indeed you can still use for custom additive loading using don't destroy on load. and then you manually managed all your objects for when they need to be destroyed.

Bye,

 Jean