Destroy deactivated instances

Discussion in 'Programming' started by NoFontNL, Jan 15, 2020.

  1. NoFontNL

    NoFontNL Member

    Joined:
    Feb 10, 2018
    Posts:
    321
    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?
     
  2. Binsk

    Binsk Member

    Joined:
    Jun 22, 2016
    Posts:
    650
    Activate it then destroy it.
     
  3. NoFontNL

    NoFontNL Member

    Joined:
    Feb 10, 2018
    Posts:
    321
    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.
     
  4. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    4,172
    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.
     
  5. stainedofmind

    stainedofmind Member

    Joined:
    Jun 20, 2016
    Posts:
    703
    Feature. Thus was implemented quite a long time ago.
     
    BattleRifle BR55 likes this.
  6. NoFontNL

    NoFontNL Member

    Joined:
    Feb 10, 2018
    Posts:
    321
    Ah, I read somewhere that you can't use instances the same step you activate them.
     
  7. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    4,172
    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.
     
    NoFontNL likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice