garbage-collection

Are .net finalizers always executed?

Are finalizers guaranteed to be executed in .NET at some point (spare power outages and the like)? I know how GC works and that it is nondeterministic when exactly they'll run. (The search did not display good answers, so I'm adding this question in high expectation of a merge with the not-so-easy-to-discover actual answers. Apart from ...

.NET: Way to determine if object has any references to it?

Q. Is there a way to find out if an object has any "strong references" to it? Raymond Chen hinted that a solution might be possible: You want to know whether the reference count is zero or nonzero. For that, use WeakReference. Notes i have a "weak reference" to the object (using a WeakReference). If i had a strong referenc...

.NET version of Java's assertGC: Unit tesing memory leaks

I am trying to write a unit test using .NET 4 to ensure that an object can be garbage collected after some code is run. In Java, I would use assertGC to ensure that a weak reference is collected. How can I write this type of test for .NET? I have tried keeping a WeakReference to the object and calling GC.Collect(), but as you'd expect, ...

What conditions would prevent the JVM from running a FULL Garbage Collection?

What conditions would prevent the JVM from running a FULL Garbage Collection when the CPU is at 5% to 8% load? I am seeing a constant shallow GC cycle, but not able to tune the JVM to want to run FULL GC. Where can I go to find the conditions that the JVM says "I am too busy to run". ...

What are the fundamental differences between garbage collection in C# and Java?

I had some very wrong sounding advice recently from a "senior" developer/coworker regaurding the C# garbage collector such as... "You need to use destructors everywhere in C# because the garbage collector cannot be relied upon." "The C# garbage collector cannot be thought of like the Java garbage collector". This sounds extremely fis...

How garbage collection works on object references?

I am confused about garbage collection process on objects. object A = new object(); object B = A; B.Dispose(); By calling a Dispose on variable B only, the created object will not be garbage collected as the object is still has referenced by A. Now does the following code work same as above? public static image Test1() { ...

Do I need to explicity unload an assembly I loaded dynamically?

I am using some .NET assemblies another developer wrote for use from an older VB6 application. They are only used for some of our customers so I am using the Assembly.LoadFrom(file) method and invoking the methods. I am worried about unloading / releasing the objects after I make the calls. Do I need to do something explicitly, or will t...

Recycling bitmaps/managing memory effectively.

I have a tile based image viewer which scrolls and zooms. Everything works fine...but when the gc fires up there is a bit of a lag I want to get rid of. At the moment, I have no recycling method to my bitmaps for the tiles not onscreen anymore. Would it make a difference if I did recycle the bitmaps once they go off screen using recy...

Sun Java jstat does not work .. sometimes !

I frequently use jstat to obtain GC related statistics. However, there are times when I simply cannot obtain any of the statistics from a JVM. It just says that it cannot find the process id, even though its the correct id. Digging slightly deeper, it seems to be related to the "/tmp/hsperfdata" related files. On servers that have this ...

What are the kind of variables that must be disposed? (.NET/Java)

Three questions: What kind of variables should be disposed manually in .NET/Java? I know that SqlConnection should always be either disposed manually or used in a using{} block. Is it right? What are the other kind of variables that should be disposed? I read somewhere that unmanaged code must be disposed manually. Is that right? What ...

Scalability of the .NET 4 garbage collector

I recently benchmarked the .NET 4 garbage collector, allocating intensively from several threads. When the allocated values were recorded in an array, I observed no scalability just as I had expected (because the system contends for synchronized access to a shared old generation). However, when the allocated values were immediately disca...

C# Destructor not working as expected

Hi, Please see the code below. I expect it to print either 10 because I have explicitly invoked the garbage collector. But I always get either a 0 or 20 as output. Why is that? void Main() { Panda[] forest_panda = new Panda[10]; for(int i=0; i<forest_panda.GetLength(0);i++) { forest_panda[i]=new Panda("P1"); } ...

Question about Garbage Collection in Java.

Suppose I have a doubly linked list. I create it as such: MyList list = new MyList(); Then I add some nodes, use it and afterwards decide to throw away the old list like this: list = new MyList(); Since I just created a new list, the nodes inside the old memory area are still pointing to each other. Does that mean the region with t...

Do I need to implement a dispose or finalize in my objects?

For too long I let the garbage collector do its magic, removing all responsibilities from my self. Sadly it never turned into an issue... So I never gave a second thought to the subject. Now when I think about it I don't really understand what the "dispose" function really does and how and when it should be implemented. The same quest...

Why does a WPF UserControl with a binding not get Garbage Collected?

Our application adds and removes WPF (4.0) UserControls from it's main window, and we've noticed that they are not getting Garbage Collected (via WeakReferences that never return null). It seems that if a UserControl has a binding this occurs, even if the control was never added to the tree. The simplest reproduction in a console applica...

Foundation tool OS X Service, Garbage Collection, MacRuby: why my NSRunLoop won't loop in acceptInputForMode:beforeDate:?

I'm writing an OS X Service with MacRuby. It upcases the selected text. It mostly works, but… well, here's all of it: #!/usr/local/bin/macruby # encoding: UTF-8 framework 'Foundation' framework 'AppKit' class KCUpcase def upcase(pasteboard, userData: s_userdata, error: s_error) incoming_string = pasteboard.stringForType "public.u...

Resource garbage collected too early

I've created a PHP extension with SWIG and everything works fine, but I'm observing some strange garbage collection behavior when chaining method calls. For example, this works: $results = $response->results(); $row = $results->get(0)->iterator()->next(); printf('%s %s' . "\n", $row->getString(0), $row->getString(1)); But this seg fau...

What versions of java are slow for gc logging?

I've been told by my company's support team that some versions of java have a significant performance impact when we turn on -verbose:gc. However I can't figure out if this is the case or not. Was this logging slow(ish) at some point, and when did it stop? The reason I ask is that there's some hesitation about applying this to a produ...

android garbage collector lingo.

Trying to find some information on the GC. In my log i see these entrie often: 08-19 22:35:27.513: DEBUG/dalvikvm(1981): GC_EXPLICIT freed 93 objects / 3160 bytes in 999ms 08-19 22:35:28.256: DEBUG/dalvikvm(2331): GC_FOR_MALLOC freed 15082 objects / 523496 bytes in 47ms whats the difference between the 2? ...

JVM and Memory Usage - JRun server not using full PSPermGen allocation?

Hi there I'm trying to understand why out ColdFusion 9 (JRun) server is throwing the following error: java.lang.OutOfMemoryError: requested 32756 bytes for ChunkPool::allocate. Out of swap space? The JVM arguments are as follows: -server -Dsun.io.useCanonCaches=false -XX:MaxPermSize=192m -XX:+UseParallelGC - I had jconsole runni...