object.set_garbage_collection_disabled

This function can be used to enable and disable garbage collection for individual objects after they have been created. However, it only works if the object was not created with the never_garbage_collect flag set. Objects created with that flag cannot have garbage collection re-enabled using this function.

Arguments

disable

If this argument is 1, then garbage collection will be disabled; if it is 0, then garbage collection will be enabled.

Example

alias has_been_carried = object.number[0]
alias expire_timer     = object.timer[0]
declare object.has_been_carried with network priority low = 0
declare object.expire_timer = 60

-- pretend this is a Forge label with no name, targeted to Rocket Launchers:
alias all_rockets  = 1

-- Let's say we want to prevent dropped Rocket Launchers from
-- despawning for a full minute.

for each object with label all_rockets do
   global.player[0] = current_object.get_carrier()
   if global.player[0] != no_player then
      current_object.set_garbage_collection_disabled(0)
      current_object.expire_timer.set_rate(0%)
      current_object.expire_timer.reset()
      current_object.has_been_carried = 1
   end
   if current_object.has_been_carried == 1 and global.player[0] == no_player then
      current_object.set_garbage_collection_disabled(1)
      current_object.expire_timer.set_rate(-100%)
      if current_object.expire_timer.is_zero() then
         current_object.set_garbage_collection_disabled(0)
         current_object.has_been_carried = 0
      end
   end
end

See also