Garbage collection problems? (OutOfMemoryException) [closed]

So... I've been using Processing to do a little MIDI work. One particular object I was particularly excited to do was re-create the effect of an Animusic-esque marble machine. This, of course, means I have to create my own classes, and in particular, I need a lot of marbles - which is likely the source of my pain.

Running Processing (3.3) with the default memory allocation allows me to render approximately 3000 frames before running out of memory. I then extended the memory to 8 GB, but the result was no different: 3000 frames later, crash. Now, I know for sure that the only new objects created happen during startup, and when a marble is fired. I realize that it isn't incredibly efficient to generate new marbles every time I need one, but hey. Let the garbage collection do the work, amirite?

Unfortunately, it doesn't seem to like doing that. Even after wholly removing all references to each marble, it appears that they may be still residing in memory. Either that, or I'm doing something else very wrong...

Anyone have ideas as to where this sort of memory build up might be occurring? I certainly make use of a lot of ArrayLists, but again, they are reinstantiated each frame so the garbage collector should be picking them up, no?

[Update 1] I tried to implement a finalize() call in each marble. I'm now hitting 5000 frames, so it's progress - but the memory buildup continues. This time, I actually got an OpenGL exception drawing a box()... so I'm thinking that's where my problems may lay; I'm drawing two boxes per unit plus two tubes from Shapes3D per frame, 88 times for each note of the keyboard. Is that the problem?

[Update 2] I re-ran the sketch on a fresh restart, using ~4 GB RAM out of my 16 total. Still set to 8 GB limit, which it hit pretty rapidly. I was able to render about 6000 frames before it started to freeze, and it continued to eek out a couple of frames a minute. The freezes began at frame 6116, and it continued until 6180, at which all progress halted. I stopped the sketch at this point (it had been nearly 10 minutes of inactivity), but I would expect an exception to be thrown if I had let it run.

[Update 3] [Possible fix] So... bad programming practice, I know, but I added in a explicit System.gc() call every frame. Works beautifully so far - memory has not climbed an inch. Slows down work a lot, so the speed is heavily affected (~8 fps to ~3 fps), but at least this means a stable run. Of course, I assumed it was a memory issue, so we'll see if it gets stuck elsewhere.

[Update 3.1] No, still climbing, just slowly because it takes some much time to run gc(). Not fixed.

[Update 3.2] Running it without marble generation is also slowing down and building up memory use. Perhaps this is an issue with the pushMatrix and popMatrix methods?

[Update 3.3] crashed in event thread due to null java.lang.NullPointerException at processing.mode.java.runner.Runner$2.run(Runner.java:577)

[CLOSED] It was my bad; mistake in my code caused objects to be generated non-stop. Still possible GC issue at hand with Shapes3D library, but my issue is solved.

Sign In or Register to comment.