Tech Off Thread

6 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

On the topic of Object Immortality

Back to Forum: Tech Off
  • User profile image

    Let's say I have the following class:

    public class Immortal
        private static System.Collections.ArrayList immortals = new System.Collections.ArrayList();

        public Immortal()

            // rise from your grave!

    If I then do the following:

    Immortal being = new Immortal();

    being = null;


    Will the program hang waiting for an immortal object to die?

    I know that the docs don't guarantee that WaitForPendingFinalizers will ever return, but I'm just curious if this will hang it.

  • User profile image

    I imagine immortals.Add(this) would end up throwing an exception if it was to cause some sort of loop.

  • User profile image

    Create a console app (C#, obviously) using this algorithm, compile, run, attach the CLR Profiler to the process, inspect GC generations, answer your question.


  • User profile image

    Finalization is pretty fragile in CLR1.1 There are lots of things you can do to break the one and only finalizer thread, especially if you use synchronisation anywhere in the code.

    Obviously if you want an object to live forever you just hald a ref to it in a static variable.

  • User profile image

    I think this practice is more commonly referred to "object resurrection." (Seriously, google it.)

  • User profile image

    Being the junior design patterns guy -- i'd have to suggest using a "singleton" pattern...


Conversation locked

This conversation has been locked by the site admins. No new comments can be made.