GMS 2.3+ Sequences, Animation Curves, Instances and Garbage Collection

samspade

Member
Are there cases where sequences and animation curves are automatically destroyed (for example like how non-persistent instances are destroyed on room change)?

In this post Nocturn said the following:

Now, for instances, anim curves and sequences, you should still ALWAYS use the appropriate destroy functions, as they will NOT be garbage collected automatically. They are "first-class" assets, which means if you define one in code but don't use it, it's STILL taking up memory, much like a global struct or function. So when you call the destroy function you are de-referencing it completely for the GC to pick up.
I believe I understand what he means. For example, if you create an instance and never use it, GM is still tracking it so until you destroy it it is sitting there and using memory. However, for instances at least, unless they are marked persistent, they are destroyed when the room ends (and presumably then garbage collected). Is the same thing true for sequences and animation curves? I read through the manual for both sequences and animation curves (did a google search and watched tutorials as well) and probably just missed it but I couldn't see any circumstances where they are auto destroyed like with non-persistent instances on room end. Are there such cases?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
Sequence instances from assets that are in the asset browser (and animation curves) will be auto cleaned up when a room ends. However if you create your own sequence (or curve) through code, these are NOT and as such need to be destroyed on room end (unless they are in a global variable for re-use).
 

samspade

Member
Sequence instances from assets that are in the asset browser (and animation curves) will be auto cleaned up when a room ends. However if you create your own sequence (or curve) through code, these are NOT and as such need to be destroyed on room end (unless they are in a global variable for re-use).
So to clarify, if you create a sequence asset in the asset browser and then make some instance of it either by placing it in the room editor or by code using layer_sequence_create(), those instances of the sequence will be destroyed on room change as with non-persistence instances of objects. But if you create a sequence with sequence_create() that is essentially creating a sequence asset through code, and that code created sequence will not be destroyed without manually destroying it. And similarly with animation curves - those that are assets created in the IDE don't really ever get (or need to be) deleted (because you're just referencing them). But if you're creating them with animcurve_create(); then you do need to delete them.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
So to clarify, if you create a sequence asset in the asset browser and then make some instance of it either by placing it in the room editor or by code using layer_sequence_create(), those instances of the sequence will be destroyed on room change as with non-persistence instances of objects.
Yes.

But if you create a sequence with sequence_create() that is essentially creating a sequence asset through code, and that code created sequence will not be destroyed without manually destroying it.
And yes. :)

(and the same for anim curves)
 
Top