Garbage collection in .net

  • Thread starter Thread starter Reshma Prabhu
  • Start date Start date
R

Reshma Prabhu

Hello,

I am using singleton class in my application. I want that the
singleton class object onc created should be alive as long as the appliation
is running.
But when I try running my application after say 24 hours, it doesn't work. I
think the object is being killed at some instance of time. Is there any
object life time for singleton objects. i.e. the object gets garbage
collected if not accessed for long amount of time even if we have reference
to that object. If so, how to avoid it?

Thanks,
Reshma
 
Reshma Prabhu said:
Hello,

I am using singleton class in my application. I want that the
singleton class object onc created should be alive as long as the
appliation is running.
But when I try running my application after say 24 hours, it doesn't work.
I think the object is being killed at some instance of time. Is there any
object life time for singleton objects. i.e. the object gets garbage
collected if not accessed for long amount of time even if we have
reference to that object. If so, how to avoid it?

No, an object will only be collected if unreferenced. Are you sure that the
singleton is being collected? Are you using ASP.NET or winforms? Can you
provide an error message or stack trace at the failure point(preferably with
associated code)?
 
I am using ASP.Net? No error comes but the application re-creates the
object.

Thanks,
Reshma
 
Reshma Prabhu said:
I am using ASP.Net? No error comes but the application re-creates the
object.

Thanks,
Reshma

The singleton lifecycle is tied to the containing application domain, when
this one gets recycled your singleton will recycle too. Asp.net might
recycle application domains when certain conditions are met, like memory
threshold, deadlocks no response timeouts etc. You can check this by looking
at the ASP.NET perfcounters (Application restarts I guess).

Willy.
 
Back
Top