garbage-collection

When happens to value types when they're removed from a collection?

Suppose I have some simple struct like this: public struct WeightedInt { public int value; public double weight; } Then let's say I have a collection of instances of this structure: List<WeightedInt> weightedInts = new List<WeightedInt>(); As I understand value types versus reference types, value types are allocated on the ...

I heard that Python has automated "garbage collection" , but C++ does not. What does that mean?

I heard that Python has automated "garbage collection" , but C++ does not. What does that mean? ...

Clearing up large fields from memory in long lived objects

.NET 3.5, I've got some classes which stores up to 1MB of strings. Even though I need the object for a really long time I don't need to store the string for a long time. How can I truly remove the string from memory without disposing the parent object. Is it a good practice to use "myString = null" in this case? or shall wrap it in a ...

On switching out garbage collectors in Java

Recently I heard Kirk Pepperdine speak about changing garbage collectors for better performance -- but what exactly does that mean and what makes one garbage collector better or different than the other? ...

GC start and stop events

Hi, Isn't it possible to get an event when the GC begins? I want to time each individual GC so I can see if pauses in my server are due to GC or something else. The GC pauses all .NET threads while running, right? (Except the thread that it runs on, of course). How about unmanaged threads? Thanks! ...

Exceptions during Finalize(): what methodology are you using to detect garbage collector-time exceptions?

I am developing a pretty extensive system in .NET, which involves a lot of system programming. Most time, I'm using the IDisposable pattern to handle resource disposal, but sometimes this isn't applicable (or left out by mistake) and resource gets destroyed during Finalize(). This might happen in COM interop, or when destructor calls Dis...

How to handle disposable objects we don't have a reference to?

If you have a brush and pen as in: Brush b = new SolidBrush(color); Pen p = new Pen(b); and dispose them like so: b.Dispose(); p.Dispose(); How would you dispose it if it was: Pen p = CreatePenFromColor(color) which would create the brush and pen for you? I can't dispose the brush inside this method, right? Is this a method not t...

OutOfMemory, but no gcroots for many objects

We are developing a rather large Windows Forms application. In several customers' computers it often crashes with OutOfMemory exception. After obtaining full memory dump of the application moments after the exception (clrdump invoked from UnhandledException handler) I analyzed it with ".NET Memory Profiler" and windbg. The Memory Profil...

Memory issue in C#, normal use if dll is called by .Net app but astronomical if dll called from legacy app.

I have created dll in C# 3.5 which does some memory intensive matrix calculations where matrices get created and disposed a lot. Everything works fine if dll is called from .Net app but if it is called from C++ created app memory usage just climbs until the function that uses matrices is done. I guess there is a problem with a automatic ...

ORO (One Reference Only) Memory Management.

What do you think about the concept of using ORO instead of traditional Garbage Collecting? It doesn't seem to be widely adopted, and is more or less argumentative, but it can provide these benefits as I know: Synchronous execution of code: your program will always take known amoun of time to execute. Simplification of platform, you'r ...

Objective C - NSImageView, NSImage, NSBitmapImage rep object lifecycle?

I've built a video viewer that is a Safari plugin that displays video from networked devices. The viewer reads bitmap images, prepares them, and sets them on the NSImageView object as follows: NSBitmapImage *bmImg = [[NSBitmapImage alloc] initWithBitmapDataPlanes: . . .] NSImage *img = [[NSImage alloc] init]; [img addRepresentation:bmI...

How to free memory in Java?

Is there a way to free memory in Java, similar to C's free() function? Or is setting the object to null and relying on GC the only option? ...

Need help reducing the Commit size of my VB.NET Application

I have an application which I've developed which queries Active Directory information and stores about 15 properties into a Datatable which is kept in memory. I need to decrease the amount of "Commit" memory it is setting aside. The application stays active in the system tray and allows for quick searching of information along with pic...

Clearing a double-linked list.

Hi. I have a double linked list (queue) I have made on my own. I am wondering, to clear the linked list, is it enough to simply remove the head and tail references? E.g public void Clear() { Head = null; Tail = null; } I am imaging a domino effect, but I am having a hard time testing it. It WILL make the whole object appea...

Tutorial about objective-c garbage collection

I would like to understand garbage collection in objective-c. I know how to work with memory in C-like languages and in languages where I don't care about memory. But I don't understand when to use autorelease, retain, dealloc and everything else, so I get errors and memory leaks. Could someone propose me a good tutorial to understand ...

Java garbage collector - When does it collect?

What is it that determines when the garbage collector actually collects? Does it happen after a certain time or after a certain amount of memory have been used up? Or are there other factors? ...

Does using a delegate create garbage

I'm working on a game for the xbox360, using XNA. On the Xbox the garbage collector performs rather badly compared to the one on a PC, so keeping garbage generated to a minimum is vital for a smoothly performing game. I remember reading once that calling a delegate creates garbage, but now for the life of me can't find any references to...

C#: In what cases should you null out references?

The CLR Profiler can also reveal which methods allocate more storage than you expected, and can uncover cases where you inadvertently keep references to useless object graphs that otherwise could be reclaimed by GC. (A common problem design pattern is a software cache or lookup table of items that are no longer needed or are safe to r...

Is it necessary to free the memory in .Net as if in VB6?

I was reading about the Form's events in VB6 such as "Unload" "QueryUnload" and "Terminate", and about the "End" statement: http://articles.techrepublic.com.com/5100-10878%5F11-5533338.html http://visualbasic.freetutes.com/learn-vb6-advanced/lesson6/p5.html I used to have problems with a VB6 app (it calls a lot of windows' apis). When I...

JavaScript garbage collection when variable goes out of scope

Does JavaScript support garbage collection? For example, if I use: function sayHello (name){ var myName = name; alert(myName); } do I need to use "delete" to delete the myName variable or I just ignore it? ...