garbage-collection

Garbage Collecting objects which keep track of their own instances in an internal Map

In the constructor of my class, I map the current object (this), along with its key (a string entered as a parameter in the constructor) into a static LinkedHashMap so I can reference the object by the string anywhere I might need it later. Here's the code (if it helps): public class DataEntry { /** Internal global list of DataEntr...

Are there Weak References in .NET?

I would like to keep a list of a certain class of objects in my application. But I still want the object to be garbage collected. Can you create weak references in .NET? For reference: Garbage Collecting objects which keep track of their own instances in an internal Map Create a weak reference to an object Answer From MSDN: To e...

Should I use Objective-C garbage collection when writing for 10.5+?

When writing fairly typical Mac code in an OS X 10.5+ environment, what are the disadvantages to using garbage collection? So far everything else I've written has been either 10.4 compatible or on the iPhone, so I've become fairly comfortable with retain/release, but now that I'm working on a larger project that's 10.5 only I'm wonderin...

When does CLR say that an object has a finalizer ?

I know that in C#, if you write ~MyClass(), this basically translates to override System.Object.Finalize(). So, whether you write the destructor or not, every type in CLR will have a Finalize() method in it (of System.Object at least). 1] So, does it mean that, every object, by default, has a finalizer ? 2] What is the basis for the CL...

Memory leaks in newly created Cocoa app when using Garbage Collection?

I decided to use the GC for memory management for my latest Cocoa project, and I discovered something interesting--if I create a brand new Cocoa app project in Xcode, turn GC to supported or required (I tried both), build, and run it it leaks, it shows memory leaks! Mostly large numbers of tiny leaks of objects of type NSCFData, General...

Garbage collection when using anonymous delegates for event handling

UPDATE I have combined various answers from here into a 'definitive' answer on a new question. Original question In my code I have an event publisher, which exists for the whole lifetime of the application (here reduced to bare essentials): public class Publisher { //ValueEventArgs<T> inherits from EventArgs public event Eve...

GC contains lots of pinned objects after a while.

I have a strange phenomenon while continuously instantiating a com-wrapper and then letting the GC collect it (not forced). I'm testing this on .net cf on WinCE x86. Monitoring the performance with .net Compact framework remote monitor. Native memory is tracked with Windows CE Remote performance monitor from the platform builder toolkit...

Diagnosing "% Time in Garbage Collection" Problems

I have an ASP.NET 2.0 application that spends an excessive amount of time in garbage collection, over 40%, when load tested on a production grade server (dual quad-core, 4g). I have been trying to isolate the problem but it is a large, complex code base making for slow going. There are no GC.Collect() calls. Which tools, techniques, e...

Do I still need to learn about managing memory now that Objective-C/Cocoa has Garbage collection?

So I finally dusted off my Objective-C/Cocoa books.. turns out they are nearly 7 years old! With Objective-C 2.0 now having garbage collection, how important are the chapters on Memory Management? How much of a difference has Garbage Collection made? ...

Question about the Java Garbage Collector, nulls and memory leaking.

Suppose I'm implementing a queue in java and I have a reference to the initial node, called ini and another to the last one, called last. Now, I start inserting objects into the queue. At one point, I decide I want an operation to clear the queue. Then I do this: ini = null; last = null; Am I leaking memory? The nodes between ini and ...

Containment Tree ?

OK thought I understood IDipose but just reading the best practices section of Accelerated VB.NET and it states that "The object doesn't contain any objects that implement iDispose, so you don't need to iterate through the containment tree calling iDispose" Is this "containment tree" just what the program know's he has used and then dis...

GC in multithreaded environment

How to do garbage collection in a program that consist from multiple threads or processes? I also like to know how can I scan the stack from each of those threads and processes? Does each process require it's own garbage collection routine? Is it a good idea to run the garbage collector in a separate thread/process from the actual prog...

When might you not want to use garbage collection?

Garbage collection has been around since the early days of LISP, and now - several decades on - most modern programming languages utilize it. Assuming that you're using one of these languages, what reasons would you have to not use garbage collection, and instead manually manage the memory allocations in some way? Have you ever had to...

How does Java Garbage collector handle self-reference?

Hopefully a simple question. Take for instance a Circularly-linked list: class ListContainer { private listContainer next; <..> public void setNext(listContainer next) { this.next = next; } } class List { private listContainer entry; <..> } Now since it's a circularly-linked list, when a single elemnt is added, it ...

Stack,Static and Heap in C++

I've searched, but I've not understood very well these three concepts. When do I have to use dynamic allocation (in the heap) and what's its real advantage? What are the problems of static and stack? Could I write an entire application without allocating variables in the heap? I heard that others languages incorporate a "garbage coll...

Error Dialog Not Being Destroyed

I am working on a project that is using a JTable to display, among other things, a column of dates. We needed validation for the user input for dates, so I have implemented a combination of masking for format validation and parsing for actual date validation. I have done this using a custom CellEditor for the date column. Inside my Mask...

What happens to an IDisposable object created in the middle of a statement that I cannot explicity call Dispose() on?

Say I'm working with Sharepoint (this applies to other object models as well) and in the middle of my statement, I call a method, in this case "OpenWeb()", which creates an IDisposable SPWeb object. Now, I cannot call Dispose() on the SPWeb object because I don't have the reference to it. So do I need to be concerned about this leaking ...

Garbage collection for ValueType wrappers

Quoting from the MSDN Link for ValueType Class In cases where it is necessary for a value type to behave like an object, a wrapper that makes the value type look like a reference object is allocated on the heap, and the value type's value is copied into it. The wrapper is marked so the system knows that it contains a value type. Th...

Is garbage collection supported for iPhone applications?

Does the iPhone support garbage collection? If it does, then what are the alternate ways to perform the operations that are performaed using +alloc and -init combination: NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:xmlData]; UIImage *originalImage = [[UIImage alloc] initWithData:data]; detailViewController = [[[DetailView...

Strategies for the diagnosis of Java memory issues

Hello, I've been tasked with debugging a Java (J2SE) application which after some period of activity begins to throw OutOfMemory exceptions. I am new to Java, but have programming experience. I'm interested in getting your opinions on what a good approach to diagnosing a problem like this might be? This far I've employed JConsole to ...