PC Review


Reply
Thread Tools Rate Thread

How to avoid garbage collection.

 
 
jkalyansagar@gmail.com
Guest
Posts: n/a
 
      20th Apr 2009
I need to maintain an object, that should not be collected by garbage
collector. This object will have lot of centralized data of
application.But i don't want to create static object. Please let me
know, is there any way to achieve it.
 
Reply With Quote
 
 
 
 
Jesse Houwing
Guest
Posts: n/a
 
      20th Apr 2009
Hello (E-Mail Removed),

> I need to maintain an object, that should not be collected by garbage
> collector. This object will have lot of centralized data of
> application.But i don't want to create static object. Please let me
> know, is there any way to achieve it.


As long as it is referenced by you application, it will not be garbage collected.
What makes you afraid that it might be?
--
Jesse Houwing
jesse.houwing at sogeti.nl


 
Reply With Quote
 
ja_1410@yahoo.com
Guest
Posts: n/a
 
      20th Apr 2009
On Apr 20, 8:09*am, jkalyansa...@gmail.com wrote:
> I need to maintain an object, that should not be collected by garbage
> collector. This object will have lot of centralized data of
> application.But i don't want to create static object. Please let me
> know, is there any way to achieve it.


Maybe just use "fixed" keyword. This is generally used for pointers,
but fixes object in memory. I'm not sure if this is what you are
looking for.
 
Reply With Quote
 
Alberto Poblacion
Guest
Posts: n/a
 
      20th Apr 2009
<(E-Mail Removed)> wrote in message
news:469aa94d-c059-4601-83d5-(E-Mail Removed)...
>I need to maintain an object, that should not be collected by garbage
> collector. This object will have lot of centralized data of
> application.But i don't want to create static object. Please let me
> know, is there any way to achieve it.


Objects in .Net are only garbage-collected after they become unreachable. As
long as your program keeps a reference to the object it is "reachable"
through that reference, and therefore it will not be collected.

 
Reply With Quote
 
Hans Kesting
Guest
Posts: n/a
 
      20th Apr 2009
After serious thinking (E-Mail Removed) wrote :
> I need to maintain an object, that should not be collected by garbage
> collector. This object will have lot of centralized data of
> application.But i don't want to create static object. Please let me
> know, is there any way to achieve it.


Why don't you want to create a "static object" (i guess you mean
'singleton')? Some other requirement that you didn't tell?

Hans Kesting


 
Reply With Quote
 
Pavel Minaev
Guest
Posts: n/a
 
      20th Apr 2009
On Apr 20, 6:05*am, ja_1...@yahoo.com wrote:
> > I need to maintain an object, that should not be collected by garbage
> > collector. This object will have lot of centralized data of
> > application.But i don't want to create static object. Please let me
> > know, is there any way to achieve it.

>
> Maybe just use "fixed" keyword. This is generally used for pointers,
> but fixes object in memory. I'm not sure if this is what you are
> looking for.


"fixed" can _only_ be used to declare local variables of pointer
types. Besides, it has nothing to do with keeping the objects alive
for GC purposes; it merely prevents the GC from moving the object
pointed to around during compacting phase.
 
Reply With Quote
 
Ignacio Machin ( .NET/ C# MVP )
Guest
Posts: n/a
 
      20th Apr 2009
On Apr 20, 8:09*am, jkalyansa...@gmail.com wrote:
> I need to maintain an object, that should not be collected by garbage
> collector. This object will have lot of centralized data of
> application.But i don't want to create static object. Please let me
> know, is there any way to achieve it.


Hi,

If you do not want it to be static, how you will make a reference to
it?
You like it or not, somewhere , something will have to be static
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to avoid garbage collection. jkalyansagar@gmail.com Microsoft C# .NET 3 21st Apr 2009 03:43 AM
garbage collection =?Utf-8?B?w5ZtZXIgS1VM?= Microsoft Dot NET 14 16th May 2005 09:42 AM
Garbage Collection - I already took it out! Mythran Microsoft ASP .NET 4 30th Mar 2004 02:51 PM
Garbage Collection Michael Hart Microsoft VB .NET 4 30th Mar 2004 11:53 AM
Re: ADO.Net and Garbage Collection Marina Microsoft ADO .NET 0 17th Mar 2004 04:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:37 PM.