Destroy deactivated instances

N

NoFontNL

Guest
Deactivated instances can't be accessed by using a with() statement.
Let's say I have inst = instance_create(x,y,oInstance);
I can use dot operations to change variables and stuff, but is there a way to still execute code from them when I have the exact instance ID?
 
N

NoFontNL

Guest
Activate it then destroy it.
When I use any of the instance_activate_...() functions, then the instance is not activated immediately, but I can use the instance in the next step. Since there is still a way to access it's variables, the instance is not completely destroyed from memory. I wondered if there would still be a way to run code from it. I'm trying to get the instance destroyed before the next step occurs, because other code will run first. For example an object that loops through all currently activated instances and does something with the information.
 

Yal

🐧 *penguin noises*
GMC Elder
What sort of code would you need to execute, anyway?

Also, instances are accessible right after an instance_activate() call. I've used this behavior in some of my projects. Under the hood, active and inactive instances are just two lists, and the functions move them from one list to the other. with loops and the event-execution loop only care about the active list. Using the dot notation bypasses the list altogether, which is why you can read and write variables using the dot notation even on inactive instances. I can't tell if it's a bug or a feature.

The Cleanup event is run when an instance is permanently removed, no matter how, so if you worry about data structures or surfaces (or other potential memory-leak sources) you could use that and then don't worry how the instance is destroyed - things like leaving the room also triggers it.
 
N

NoFontNL

Guest
What sort of code would you need to execute, anyway?

Also, instances are accessible right after an instance_activate() call. I've used this behavior in some of my projects. Under the hood, active and inactive instances are just two lists, and the functions move them from one list to the other. with loops and the event-execution loop only care about the active list. Using the dot notation bypasses the list altogether, which is why you can read and write variables using the dot notation even on inactive instances. I can't tell if it's a bug or a feature.

The Cleanup event is run when an instance is permanently removed, no matter how, so if you worry about data structures or surfaces (or other potential memory-leak sources) you could use that and then don't worry how the instance is destroyed - things like leaving the room also triggers it.
Ah, I read somewhere that you can't use instances the same step you activate them.
 

Yal

🐧 *penguin noises*
GMC Elder
Ah, I read somewhere that you can't use instances the same step you activate them.
I think that text meant that those instances won't have a step event that step if you activate them in a step event... I've never really had any concerns with that since I run my activation logic in an alarm to reduce overhead, but I guess it could trip things up.
 
Top