Re: [Flashcoders] "clearing" variables from memory after use...
David Rorex schrieb: my_var = null; and delete my_var; should do exactly the same thing...delete doesn't actually delete the object, only the reference to the object. it doesn't get removed from memory until later (when the GC feels like it) Well, we observe different behaviour here: After unloading and removing a dynamically loaded mc, the variables used within that mc are all set to "null" - the debugger still shows they are there, and they are not null. Then we changed the code to _delete_ all variables onUnload, and now the variables get cleared. I must add that the corresponding variables used by the mc reside at _global, but this shouldn't make any difference, should it? Best regards, Roman. -- --- gosub communications gmbh | fredersdorfer str. 10 | 10243 berlin t [030] 29 66 88 81 | f [030] 29 66 88 84 | http://www.gosub.de --- ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] "clearing" variables from memory after use...
j.c.wichman schrieb: Hi Roman, You describe my_var =null as being useless, but this should be enough for the garbage collector to come along and reclaim an object? With respect to the static issue, what do you mean with 'static instances' ? Could u provide an example of such an object with isn't reclaimed? Sorry, not at hand. I remember my first use of static values (NOT instances, of course - excuse me if I said so, that's dumb of course) with a gaming app, where I made a sokoban-style game within the whole thing. This sokoban game was an instance of my sokoban-class, using _some_ static values. After the sokoban was over, the game mc has been removed (removeMovieClip) and loaded anew when the player wanted to play another round. The times after the first run gave me the headaches, until I stopped using _any_ static value in my class. Another weird example out of my actual project: my_loader is an instance of my preloading-manager-class, the array created_clips stores references to the successfully loaded mcs: At some place - i.e. when stopping the game represented by the mc that has been loaded by my "my_loader" - the game should be removed from memory (for performance reasons): my_loader.created_clips[names.game_1].undloadMovie(); my_loader.created_clips[names.game_1].removeMovieClip(); _root.host.debug("GameHost.gameStop(" + movie_name + "): my_loader.created_clips["+names.game_1+"] == "+my_loader.created_clips[names.game_1]); _root.host.debug("GameHost.gameStop(" + movie_name + "): typeof(my_loader.created_clips["+names.game_1+"]) == "+typeof(my_loader.created_clips[names.game_1])); The debug-call (simply directs text to a floating text field for debugging) yields the following: GameHost.gameStop(IcefallClimbing): my_loader.created_clips[IcefallClimbing] == _level0.gamecontainer.IcefallClimbing GameHost.gameStop(IcefallClimbing): typeof(my_loader.created_clips[IcefallClimbing]) == movieclip So you really should digest this: The loaded mc is first unloaded, then removed, and still it sits there in memory as a moveclip! I'm seeing ghosts When I - after unloding and removing - delete my_loader.created_clips[names.game_1]; then of course my debug states it is "null", but I'm not really sure, whether it really is null, or whether there simply isn't any variable left that could point to my unloaded and then removed movieclip still residing in memory... Unfortunately I'm not really wondering whether it's a bug or a feature - it's special, it's Flash. Best regards, Roman. -- --- gosub communications gmbh | fredersdorfer str. 10 | 10243 berlin t [030] 29 66 88 81 | f [030] 29 66 88 84 | http://www.gosub.de --- ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] "clearing" variables from memory after use...
my_var = null; and delete my_var; should do exactly the same thing...delete doesn't actually delete the object, only the reference to the object. it doesn't get removed from memory until later (when the GC feels like it) Well, technically they do *slightly* different things, but usually with almost the same end result. Delete destroys the reference, allowing the object to be cleaned up by the GC (assuming there are no other references to it), and assigning null to the reference reassigns the reference to a different object, so your original object will be cleaned up by the GC, however, the reference will still exist, it just points to null. Delete actually dumps both the object and the reference (eventually, when the GC gets around to it), while assigning null only dumps the object (again, when the GC gets to it). ryanm ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] "clearing" variables from memory after use...
my_var = null; and delete my_var; should do exactly the same thing...delete doesn't actually delete the object, only the reference to the object. it doesn't get removed from memory until later (when the GC feels like it) var obj1 = {blah:"hello"}; var obj2 = obj1; delete obj1; trace(obj2.blah); // traces 'hello' ... the object was never deleted, only the reference -David R On 2/1/06, j.c.wichman <[EMAIL PROTECTED]> wrote: > > > Hi Roman, > You describe my_var =null as being useless, but this should be enough for > the garbage collector to come along and reclaim an object? > With respect to the static issue, what do you mean with 'static instances' > ? > Could u provide an example of such an object with isn't reclaimed? > > Thanks, > Hans > > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Roman > Blöth > Sent: Wednesday, February 01, 2006 6:09 PM > To: Flashcoders mailing list > Subject: Re: [Flashcoders] "clearing" variables from memory after use... > > dls schrieb: > > Might be counting angels on a pin head here, but: > > > > if I set alot ( think hundreds) of _global variables such as: > > _global.state1 = Wisconsin; > > > > I assume they slow the performance of my player. > > Is there a way to clear them after use? > > (or more specifically, the ones I don't need -- I could figure out how > > to specify that in the code) > Oh my, this really is a matter in Flash... Since we have often experienced > variable's values not being cleared after use, we do the > following: > > my_var = null; // This first step probably is useless, but ALWAYS use > DELETE! > delete my_var; > > If the value contained within the variable is a movieclip, then make sure > that this mc has an "onUnload"-handler that does the above with all > variables and to avoid instances from floating in memory after having > deleted, unloaded and removed them, if possible don't use static values! > > I have made the experience that static instances stay in memory after > there > is no reference to them left, since I set them all to null and then > deleted > them. Then, when I re-create an instance of such static stuff, it isn't > created anew, but Flash uses the old piece that rests in memory. > > Maybe it's just that I don't really, really understand the concept of > "static", but I know it can lead to unpredictable and hard-to-track > errors. > > > Best regards, > Roman. > > -- > > --- > gosub communications gmbh | fredersdorfer str. 10 | 10243 berlin > t [030] 29 66 88 81 | f [030] 29 66 88 84 | http://www.gosub.de > --- > > ___ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > ___ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] "clearing" variables from memory after use...
Hi Roman, You describe my_var =null as being useless, but this should be enough for the garbage collector to come along and reclaim an object? With respect to the static issue, what do you mean with 'static instances' ? Could u provide an example of such an object with isn't reclaimed? Thanks, Hans -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Roman Blöth Sent: Wednesday, February 01, 2006 6:09 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] "clearing" variables from memory after use... dls schrieb: > Might be counting angels on a pin head here, but: > > if I set alot ( think hundreds) of _global variables such as: > _global.state1 = Wisconsin; > > I assume they slow the performance of my player. > Is there a way to clear them after use? > (or more specifically, the ones I don't need -- I could figure out how > to specify that in the code) Oh my, this really is a matter in Flash... Since we have often experienced variable's values not being cleared after use, we do the following: my_var = null; // This first step probably is useless, but ALWAYS use DELETE! delete my_var; If the value contained within the variable is a movieclip, then make sure that this mc has an "onUnload"-handler that does the above with all variables and to avoid instances from floating in memory after having deleted, unloaded and removed them, if possible don't use static values! I have made the experience that static instances stay in memory after there is no reference to them left, since I set them all to null and then deleted them. Then, when I re-create an instance of such static stuff, it isn't created anew, but Flash uses the old piece that rests in memory. Maybe it's just that I don't really, really understand the concept of "static", but I know it can lead to unpredictable and hard-to-track errors. Best regards, Roman. -- --- gosub communications gmbh | fredersdorfer str. 10 | 10243 berlin t [030] 29 66 88 81 | f [030] 29 66 88 84 | http://www.gosub.de --- ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] "clearing" variables from memory after use...
Thanks Roman! I will make it a practice to start dumping the variables after I don't need them! --dan Roman Blöth wrote: dls schrieb: Might be counting angels on a pin head here, but: if I set alot ( think hundreds) of _global variables such as: _global.state1 = Wisconsin; I assume they slow the performance of my player. Is there a way to clear them after use? (or more specifically, the ones I don't need -- I could figure out how to specify that in the code) Oh my, this really is a matter in Flash... Since we have often experienced variable's values not being cleared after use, we do the following: my_var = null; // This first step probably is useless, but ALWAYS use DELETE! delete my_var; If the value contained within the variable is a movieclip, then make sure that this mc has an "onUnload"-handler that does the above with all variables and to avoid instances from floating in memory after having deleted, unloaded and removed them, if possible don't use static values! I have made the experience that static instances stay in memory after there is no reference to them left, since I set them all to null and then deleted them. Then, when I re-create an instance of such static stuff, it isn't created anew, but Flash uses the old piece that rests in memory. Maybe it's just that I don't really, really understand the concept of "static", but I know it can lead to unpredictable and hard-to-track errors. Best regards, Roman. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] "clearing" variables from memory after use...
dls schrieb: Might be counting angels on a pin head here, but: if I set alot ( think hundreds) of _global variables such as: _global.state1 = Wisconsin; I assume they slow the performance of my player. Is there a way to clear them after use? (or more specifically, the ones I don't need -- I could figure out how to specify that in the code) Oh my, this really is a matter in Flash... Since we have often experienced variable's values not being cleared after use, we do the following: my_var = null; // This first step probably is useless, but ALWAYS use DELETE! delete my_var; If the value contained within the variable is a movieclip, then make sure that this mc has an "onUnload"-handler that does the above with all variables and to avoid instances from floating in memory after having deleted, unloaded and removed them, if possible don't use static values! I have made the experience that static instances stay in memory after there is no reference to them left, since I set them all to null and then deleted them. Then, when I re-create an instance of such static stuff, it isn't created anew, but Flash uses the old piece that rests in memory. Maybe it's just that I don't really, really understand the concept of "static", but I know it can lead to unpredictable and hard-to-track errors. Best regards, Roman. -- --- gosub communications gmbh | fredersdorfer str. 10 | 10243 berlin t [030] 29 66 88 81 | f [030] 29 66 88 84 | http://www.gosub.de --- ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] "clearing" variables from memory after use...
Might be counting angels on a pin head here, but: if I set alot ( think hundreds) of _global variables such as: _global.state1 = Wisconsin; I assume they slow the performance of my player. Is there a way to clear them after use? (or more specifically, the ones I don't need -- I could figure out how to specify that in the code) Thanks for putting up with my ignorance... --dan ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders