Memory Leak in my Cinematics Based application

I load a LOT of events into my cinematic buffer, which is okay initially but at some point it gets REALLY slow and I start witnessing hiccups. Note that the number of objects in the scene remains the same (and not so many); I just add/delete spatials to the scene and animate them.

While debugging I noticed that the cinematic buffer keeps increasing but is never emptied. Could that be the reason I get the hiccups in animation followed by some hangs eventually?

The same case without the inserts/removal of spatials (i.e. the same spatials move around) works perfectly. The problem has to do with adding/removing objects to the scene. Is there an efficient way to do so? any ideas?

PS: this has nothing to do with optimization or the number of vertices as I have a high frame rate.

What do you call the cinematic buffer?

If it’s the list of events added to the cinematic, why would it empty itself?

If you keep adding things into it…things stack up…

I can add a removeEvent method if you want, but you’ll have to handle the cleaning yourself.

but my question more specifically , is could this stack overload cause a behavior like the one I described?

@garnaout said:
but my question more specifically , is could this stack overload cause a behavior like the one I described?

i don't know but clearing the event list may help you figure it out.

yeah it’s definitely it, after checking my resource monitor, it seems that the buffer keeps increasing until the animation crashes… I just need to find a neat way to delete these events.

when you say adding removeEvent method, are you suggesting that I call it every time I finish reading an event from the cinematic buffer?

I don’t really see why you keep adding events and expect them to be removed automatically…

anyway, I’ll add a way to remove events because it can be handy for many situations.

1 Like

cool! let me know when you do so I get that nightly…


done in last SVN revision.


this may sound silly but if I added a cinematic event, when would it be safe to remove it? Is it after complete completion of that event or is it safe to remove it once it started?

when it’s done…

How many event do you add to the cinematic to make it crash?..i wonder…

I wonder what in general you do so that it justifies spending all this time on the cinematic system instead of just moving the objects yourself ^^

@nehon - A LOT :slight_smile: yeah I tried it, it doesn’t seem quite straight forward, having tons of concurrency errors when removing events. I’ll research more. thanks a lot though

@normen - I am using Cinematics to read trace files for animation purposes of something else I’m working on (not a game). And it seems like the ideal tool to do that once I tweak it around

thanks guys

@garnaout said:
Note that I did fork cinematics and replaced the CinematicEventsList with a Vector and TimeLine to a ConcurrentHashmap instead of hashmap - so I won't have any threading issues. Not sure if that would cause any issues like that.

...well...good luck with that.

I am using default settings but tried ur approach and increased the direct memory size to 1024m but still the issue persists.

So I implemented an Appstate that I called Cinematic cleaner that puts all the cinematic events into a concurrentHashMap and safely removes them after they’re consumed. It works perfctly, except when monitoring the application via the resource monitor, the javaw.exe is still increasing with the lifetime of cinematics until the model crash from out of memory.

Any idea what could be causing this? @nehon I guess the experiment that I did showed that removing the cinematicevents from the list didn’t help and that’s not the issue.


another general question, when I detach objects from the rootNode, are they eventually garbage collected? I’m afraid that the geoms I am creating and deleting with these cinematic events aren’t being removed. Or in cinematics, if I remove the event from the list, shouldn’t it be garbage collected? IS there any other reference for cinematic events somewhere that I dunno about?


I checked the size of the scene using getVertexCount() and it’s not increasing throughout the animation


Are you using default heap settings? Or have you increased the max heap size?

Sounds like maybe you have a huge max heap but not a very big max direct memory?

the problem isn’t from my memory settings, there’s a memory leak somewhere that I can’t seem to figure out. This only happens when I run some method that ends up adding and removing geometries to the scene.

@garnaout said:
the problem isn't from my memory settings, there's a memory leak somewhere that I can't seem to figure out. This only happens when I run some method that ends up adding and removing geometries to the scene.

But direct memory can look like a memory leak since it is only freed when regular GC runs. So if your heap is set really large then direct memory is never GC'ed even though you have none left.

I made a quick test that adds and remove cinematic events to a cinematic over time, and i didn’t notice any leak, the memory is GCed correctly.

Are you sure you don’t keep a reference on the events you remove from the cinematic?

Or something like that, somehow a cyclic ref somewhere that prevent objects to be GCed?

1 Like