Re: Garbage Collection



Eric Grange wrote:
Huh? What are you talking about?

Letting the GC be able to recycle the memory of parts of a collection/datastructure before the whole collection/datastructure itself leaves the scope.

If you're only dealing with small collections/datastructures (relatively to available memory) that's not an issue, but whenever that's not the case, that's IME the #1 source of memory usage "bloat" in your typical .Net/Java apps, leading to "spikes" in memory usage until the whole processing has completed.

F.i. one recently encountered situation, if you have something like

{
list = new ListOfSomething()
for all item in list
item.DoSomeStuff()
}

where DoSomeStuff() involves allocation of memory referred in item (such as data being pulled from a DB, work structures, etc.), said memory won't be recoverable until the for loop has ended, unless the loop is changed to include nil'ing:
list[index].DoSomeStuff()
list[index] = nil;
which would be a list[index].free in a non-GC world.

Of course that can be a little more involved to solve if instead of a list, you actually get an iterator that maintains the list internally...

Eric


Good example. Say some programmer with a limited data set and a non-deterministic garbage collector has to iterate through this 10 times during testing. No problem, the ndgc works fine. But when you put that same situation in the real world where you might have to iterate through 50,000 items, periodically the user is going to curse the computer when he can't move the mouse because some background garbage collection process steals his cpu while managing all this memory that has been abandoned.

I anticipate that some of you will come back and say "Well then he should just go ahead and deallocate the memory manually in the process.." to which I will reply "Then what's the point of having a non-deterministic garbage collector?"

I repeat, good coding practice and a good, well-defined software engineering process is the best garbage collector.

Mark
.



Relevant Pages

  • Re: to dispose or not ?
    ... always have the system memory roots available. ... collector for the Gen0 and Gen1 heaps and a mark/sweep/compact collector for ... heap or compacts free space out of the heap. ... the reference from the variable to the object in the heap. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: to dispose or not ?
    ... always have the system memory roots available. ... It also means that MS took some shortcuts in the garbage collector to improve the performance of finalizers. ... the reference from the variable to the object in the heap. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Memory Allocation?
    ... we shouldn't need access to the Garbage Collector ... I answered earlier that the *way* CPython allocates and uses memory it ... from writing a memory profiler;) ...
    (comp.lang.python)
  • Re: clustering of objects in a VM
    ... I.e., if during say, an ephemeral collection cycle, two objects were ... accessed within the same ephemeral cycle the collector knows what memory was ... > references in the system to objectB and objectC. ...
    (comp.lang.smalltalk)
  • Re: OutOfMemory is intermittent, maybe heres why
    ... The probability of an error has some correlation with the size of the image but is not reliable. ... It's possible memory is getting fragmented and while there is a lot of free memory there isn't a free contiguous block of memory. ... Does the .Net Framework fragment its virtual memory differently under Vista than it does under XP? ... I still think it looks like the stack is getting smashed because the collector does move something when the rest of the runtime isn't ready for it to be moved. ...
    (microsoft.public.dotnet.framework.drawing)

Loading