Garbage collection in .net

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
 
D

Daniel O'Connell [C# MVP]

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)?
 
R

Reshma Prabhu

I am using ASP.Net? No error comes but the application re-creates the
object.

Thanks,
Reshma
 
W

Willy Denoyette [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top