playMaker

Author Topic: GameObject references leaked  (Read 8819 times)

DaniM

  • Playmaker Newbie
  • *
  • Posts: 4
GameObject references leaked
« on: January 26, 2012, 05:49:25 AM »
Hi, sorry if it is duplicated (I searched this topic but i havent found anything), but I have a really serious problem with "cleaning" Playmaker variables. I'm using the 1.2.1 version (I've just recently updated it, but it seems my problem is not solved or at least I don't know how to fix it)
The situation is this:

1) I start my game in a scene which don't use Playmaker (Main Menu).
2) Then a one with PM its loaded (First level for example). Some of the FSMs has actions for spawning elements (the main character, npcs, etc...All of them are prefabs references if it helps).
3) When I return to the main menu (or change to any other level), the meshes along with its materials and animations are leaked (the profiler tells me so)

extra) If I load another level (say level 2) which uses different npcs, they are leaked too. And when I come back to main menu, I've lost around 30 MB.

I`ve created the level without using playmaker just for testing (I really need this awesome tool!), and the objects are not leaked. I return to the main menu without any memory problems.
I think, this is because some static references of PlayMaker point to "something" that prevents to free the gameobject/mesh/whatever.

Is there any way to do some cleaning to avoid this annoying leaks? I need to find out a way to do it, because after a few levels, I run out of memory (is an iOS game).

Help, please!

Thanks in advance.

PS: Sorry for my bad English (it's not my mother tongue)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: GameObject references leaked
« Reply #1 on: January 26, 2012, 08:16:51 AM »
Hi,
 
Are you sure that the non playmaker scene reproduces exactly the same patterns? I did an ios project without playmaker at all, and memory was the biggest issue, I had to create a special framework to load and unload scenes so that memory properly gets collected by the GC.

try the following, load an empty scene, and then load additive your next level, so that you don't load a level on top of another one, but actually load a completly empty level ( create an empty scene, and add it the list for publishing). this really solved my memory problems.

 else, there might be indeed a memory leak with playmaker, that I don't know, never pushed it hard enough on ios and playmaker yet to witness this.

 Bye,

 Jean


DaniM

  • Playmaker Newbie
  • *
  • Posts: 4
Re: GameObject references leaked
« Reply #2 on: January 26, 2012, 08:44:29 AM »
Thanks for the answer!

Actually I'm doing this right now. I always pass through a "Loading screen" which is empty.
I'm almost sure that I'm not cleaning things of Playmaker, or I'm missing something about it.
I've profiled a lot and the problem seems to be there.

Furthermore a made a test with the same flow (the one I mention before), but instead a level of my game, an empty scene with one script that instantiates a prefab (no PM), and other one which is exactly the same but instantiating it through a Fsm action (using a PlayMakerFsm component, of course).
The one with PM produces the prefab's leak.
« Last Edit: January 26, 2012, 10:07:30 AM by DaniM »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: GameObject references leaked
« Reply #3 on: January 26, 2012, 11:41:19 AM »
Then indeed something is going on.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3999
  • Official Playmaker Support
    • LinkedIn
Re: GameObject references leaked
« Reply #4 on: January 26, 2012, 03:07:39 PM »
Hi DaniM,

I sent you an invite for the 1.3 beta. Quite a lot has changed under the hood in this update, so give it a try (backup your project first!!), and let me know if this is still a problem in 1.3.

Thanks!
Alex

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3999
  • Official Playmaker Support
    • LinkedIn
Re: GameObject references leaked
« Reply #5 on: January 26, 2012, 06:24:27 PM »
If it's still a problem in 1.3, I'd love a simple repro project...

flekoun

  • Playmaker Newbie
  • *
  • Posts: 19
Re: GameObject references leaked
« Reply #6 on: January 04, 2013, 05:46:27 AM »
Hi guys. Actually this is exactly what is happening! We have a quite big project with some FSM here and there and on the iOS the objects leaks from scene to scene! I cant believe this. I don't want to be rude or something but how much knowledge has a creator of this plugin about Garbage collector management on iOS? It behaves exactly like the founder of this thread said. Like not destroying references to objects when leaving a scene. When I have simple FSM in scene which creates a game object "Box". The Box is a prefab with a material for example. You don't even have to actually let the FSM create the "Box" Gameobject. All what is needed is let the FPS has a reference to this Game object. Ok and now you leave this scene with this FSM. What happens? You will find that there is a material in your new scene. The material the "Box" was using! Looks like the FMS is not releasing the references to the objects! Is this even possible? I can believe it but it is happening. Our project is actually crashing afer few hours of gameplay because of memory leaks. I dont want to blame Playmaker for all of it but this is happening. I am using the latest PM version 1.4 from asset store.

flekoun

  • Playmaker Newbie
  • *
  • Posts: 19
Re: GameObject references leaked
« Reply #7 on: January 04, 2013, 03:56:26 PM »
I tried to fix this on my own but there are no source codes only DLL. Oh no, please we need to fix this asap as this renders our game on iOS unusable. HELP!

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3999
  • Official Playmaker Support
    • LinkedIn
Re: GameObject references leaked
« Reply #8 on: January 05, 2013, 01:22:51 AM »
Can you send me a small repro project with repro steps? Are you seeing the leak on the device or in the editor?

flekoun

  • Playmaker Newbie
  • *
  • Posts: 19
Re: GameObject references leaked
« Reply #9 on: January 05, 2013, 03:39:36 AM »
Ok, I will try to create a small project and send it to you. The leak could be seen on both Editor and Device.

flekoun

  • Playmaker Newbie
  • *
  • Posts: 19
Re: GameObject references leaked
« Reply #10 on: January 05, 2013, 04:20:06 AM »
Here is a simple project. In the project there are 2 scenes. One with Playmaker FSM which changes materials of 2 images and creates a one particle. This is not important what asset the FSM is creating/handling whatever it is it will leak in the memory. The other scene is Empty scene.
To test the leak just run the app and click "Exit to empty scene" button. Then in the empty scene click on "List Loaded Materials". Now you will see in the console output that there are all 5 materials from scene 1 leaked. The 4 images and 1 particle effect. I tested this in Editor as well as on iOs device and behavior is the same.
Could you please fix this asap and release a hot-fix? We are in deep troubles with our distributor as the game is crashing on low memory and we could do nothing about this. I don't know your code but probably after the FSM is destroyed you are not setting its variables to NULL. Also you need set the instance of a FSM in OnDestroy() method to null. This is just my wild guess would could be wrong.

[Admin: Link removed. Please don't post projects that include Playmaker!]

« Last Edit: January 05, 2013, 09:22:09 AM by Alex Chouls »

flekoun

  • Playmaker Newbie
  • *
  • Posts: 19
Re: GameObject references leaked
« Reply #11 on: January 05, 2013, 09:33:04 AM »
[Admin: Link removed. Please don't post projects that include Playmaker!]

Sorry, didn't realized it  :-X But did you get the simple repro project??

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3999
  • Official Playmaker Support
    • LinkedIn
Re: GameObject references leaked
« Reply #12 on: January 05, 2013, 09:54:13 AM »
Yes - looking into it now...

The FSM instance is set to null in OnDestroy which should cause its variables to be garbage collected since they are no longer referenced (it shouldn't be necessary to set each one to null). Something else must be holding a reference... I should have more to report soon...

flekoun

  • Playmaker Newbie
  • *
  • Posts: 19
Re: GameObject references leaked
« Reply #13 on: January 05, 2013, 10:05:55 AM »
Ok great. Yes there must by something which is keeping a reference to FMS probably. Don't you have some static manager? Or it is enough if you somewhere store the reference to FSM. Then even if you set it to null in OnDestroy, the object is not collected as someone has still the reference to it.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3999
  • Official Playmaker Support
    • LinkedIn
Re: GameObject references leaked
« Reply #14 on: January 05, 2013, 12:06:22 PM »
Yeah. I found a stray static FSM reference in the event manager.

This means you can leak exactly one FSM if you go to a scene without any FSMs. If you sent an FSM Event in the new scene the static reference would be cleared and the old FSM would be garbage collected.

It's a pretty specific situation which is probably why it wasn't caught earlier. The bug that started this thread was fixed in 1.3 (FSM references in the FSM Logging system). This is a different bug - good catch ;)

Anyway, I'm pretty sure this is what's happening in your project (at least in the test project you sent me). I have a fix in the latest beta. I'll send you an invite.


« Last Edit: January 05, 2013, 12:07:56 PM by Alex Chouls »