Delete object

Hi
I don't remember an existing destroy method as opposite to 'new'.
=> Made my own:
# Is this correct / can it be done better?

class A
  ...
  def destroy
   self=nil
   @x=@y=nil... # necessary for vars too, if referenced indirectly from
other objects?
  end
end

a=A.new
a.destroy # instead of a=nil
(the object needs a self-destroy possibility from within inside)

Thanks
Berg

Yeah, just don’t do anything with it and either the GC will get it or the OS will get it when the process goes away.

···

On 11 Sep 2016, at 20:18, A Berger wrote:

I don't remember an existing destroy method as opposite to 'new'.
=> Made my own:
# Is this correct / can it be done better?

Hi, normally that should be enough. But what with a circular list - there
must be a way to "help" the GC. What can be done here? (Thinking of a
million of autonomous robots (objects) which get shot in a war-game..) -
There wouldn't be an external list with the retention-state for each.
Long-term new robots can only be created, if getting the memory(space) of
the dead ones :slight_smile:

thanks
Berg

···

Am 12.09.2016 04:29 schrieb "Bryce Kerley" <bkerley@brycekerley.net>:

On 11 Sep 2016, at 20:18, A Berger wrote:

> I don't remember an existing destroy method as opposite to 'new'.
> => Made my own:
> # Is this correct / can it be done better?

Yeah, just don’t do anything with it and either the GC will get it or the
OS will get it when the process goes away.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

​It might be of benefit for you to read up on weak references:

Cheers​

···

On 12 September 2016 at 17:48, A Berger <aberger7890@gmail.com> wrote:

Hi, normally that should be enough. But what with a circular list - there
must be a way to "help" the GC. What can be done here? (Thinking of a
million of autonomous robots (objects) which get shot in a war-game..) -
There wouldn't be an external list with the retention-state for each.
Long-term new robots can only be created, if getting the memory(space) of
the dead ones :slight_smile:

thanks
Berg

--
  Matthew Kerwin
  http://matthew.kerwin.net.au/

Hi
Thank you! But seems if GC starts (itself, automatically) the (living)
creatures are also destroyed. Should be only destroyed when being shot...
(Changing to weakref if shot, would allow to instead set to nil)
(Maybe GC can be used simulating a never-knowing-when-started
atomic-bomb... :slight_smile:
So perhaps there are other possibilities in this case.
- The question is how to manually set an object to nil by itself (like
self=nil), to make all existing (unknown) refs -> nil.

PS: Looks like ruby-doc search isn't working!?

Thanks!
Berg

···

Am 12.09.2016 12:48 schrieb "Matthew Kerwin" <matthew@kerwin.net.au>:

On 12 September 2016 at 17:48, A Berger <aberger7890@gmail.com> wrote:

Hi, normally that should be enough. But what with a circular list - there
must be a way to "help" the GC. What can be done here? (Thinking of a
million of autonomous robots (objects) which get shot in a war-game..) -
There wouldn't be an external list with the retention-state for each.
Long-term new robots can only be created, if getting the memory(space) of
the dead ones :slight_smile:

thanks
Berg

​It might be of benefit for you to read up on weak references:
Class: WeakRef (Ruby 2.3.1)

Cheers​
--
  Matthew Kerwin
  http://matthew.kerwin.net.au/

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

​That's why I said to read up on it :wink: If you have a game "engine" object
that holds strong refs to all the living entities they won't be GC'd; and
if all the entities have weak references to each other you won't have
cyclic references or zombie meshes.

Cheers​

···

On 12 September 2016 at 22:03, A Berger <aberger7890@gmail.com> wrote:

Hi
Thank you! But seems if GC starts (itself, automatically) the (living)
creatures are also destroyed. Should be only destroyed when being shot...
(Changing to weakref if shot, would allow to instead set to nil)
(Maybe GC can be used simulating a never-knowing-when-started
atomic-bomb... :slight_smile:
So perhaps there are other possibilities in this case.
- The question is how to manually set an object to nil by itself (like
self=nil), to make all existing (unknown) refs -> nil.

PS: Looks like ruby-doc search isn't working!?

Thanks!
Berg

--
  Matthew Kerwin
  http://matthew.kerwin.net.au/