Flint Particle System Forum - 1.0.2 Bug: Emitter's Subject to Garbage Collection Sat, 25 Dec 2010 16:15:39 +0000 http://flintparticles.org/forum/ Lussumo Vanilla 1.1.10 & Feed Publisher 1.0.2 Bug: Emitter's Subject to Garbage Collection http://flintparticles.org/forum/comments.php?DiscussionID=25&Focus=122#Comment_122 http://flintparticles.org/forum/comments.php?DiscussionID=25&Focus=122#Comment_122 Thu, 08 May 2008 01:43:57 +0100 ericr must store a reference to each Emitter object they instantiate. This is due to the fact that no reference to the Emitter is kept in the Display Hierarchy. Currently, as is visible in all demos, we get the following scenario:

Emitter -> Renderer.
Display Hierarchy -> Renderer.

Nowhere does a reference to the Emitter get stored.

I would make a motion for a re-implementation of the Emitter/Renderer setup. I would suggest [naïvely] adding an _emitters:Array field to the Renderer class. This kind of makes sense, too. Emitters are simply the logic behind the Renderer. Why not have two Renderers reference a single emitter (or multiple, for that matter)? The only thing that would need to change in the Emitter class is the following line:
_renderer.renderParticles( _particles );
Which could change to:
dispatchEvent( new FlintEvent( FlintEvent.PARTICLES_UPDATED ) );
(Alternatively you could use the ENTER_FRAME event with the Renderers and mess around with priorities or rely on the fact that you might be one frame behind the emitter... either way you're fine, really.)

Adding an emitter to the renderer would have the effect of registering the renderer for that "PARTICLES_UPDATED" event (as well as storing a reference to the Emitter in the renderer object, which is added to the Display Hierarchy and thus not a candidate for garbage collection).

Current Workaround: Store a reference to your Emitter objects as a Class variable (gah). ]]>
1.0.2 Bug: Emitter's Subject to Garbage Collection http://flintparticles.org/forum/comments.php?DiscussionID=25&Focus=123#Comment_123 http://flintparticles.org/forum/comments.php?DiscussionID=25&Focus=123#Comment_123 Thu, 08 May 2008 01:49:42 +0100 ericr Note: I would not advocate a circular reference (link the Emitter to the Renderer and the Renderer to the Emitter) as that would just increase the likeliness of memory leaks in peoples' programming. ]]> 1.0.2 Bug: Emitter's Subject to Garbage Collection http://flintparticles.org/forum/comments.php?DiscussionID=25&Focus=124#Comment_124 http://flintparticles.org/forum/comments.php?DiscussionID=25&Focus=124#Comment_124 Thu, 08 May 2008 09:04:36 +0100 Richard
I don't, however, consider this a bug in the Emitter. Any object in flash is garbage collected if there are no references to it. An emitter is no different to other objects in this respect.

I am planning a more substantial restructuring of the relationship between the renderer and the emitter, to coincide with the release of the 3D version of Flint (this version will still support 2d as well).

The changes will allow multiple renderers to display a single emitter and multiple emitters to be displayed by a single renderer. I'll write more about it and we can have a discussion when I have an alpha version to show. ]]>
1.0.2 Bug: Emitter's Subject to Garbage Collection http://flintparticles.org/forum/comments.php?DiscussionID=25&Focus=125#Comment_125 http://flintparticles.org/forum/comments.php?DiscussionID=25&Focus=125#Comment_125 Thu, 08 May 2008 16:01:47 +0100 ericr
I agree that this isn't a bug in the Emitter. It is merely an oddity resulting from the current architecture. ]]>