garbage collection (long)



hi folks, 

some month ago, i already asked for an gc implementation in GTK,
but got almost no response, so i'd like to warm up the topic now.

for those who are not familar with GC, some short explaination:

* an garbage collector is responsible for freeing memory chunks
  which are not used (referenced) any longer, so it's no longer
  the job of the developer.

* if properly implemented, the GC removes most errors situations
  with bad pointers, since once an pointer was initialized it
  will (theoretically) never point to unallocated memory.

* especially when working with complex graphs (an normal GTK 
  application already has them, even when hidden behind the ADTs),
  it makes code smaller, easier to understand, and much more stable.

* many modern languages (i.e. oberon, java, perl, php) use GCs,
  but there are also GC-based memory allocators for C or C++.

* in general there are two common methods for GCs.

  a) reference counting
     
     the GC manages an reference counter for each chunk. this counter
     is increased evry time the chunk gets referenced (pointer
assignment)
     and will be decreased when the reference is removed.
     
     this method quite is easy to implement (in C with macros or in C++
     by overloading pointer operations), is unproblematic in
multithreaded
     enviroments, but can leave some trash when using ring graphs.

  b) conservative GC

     here the GC runs from time to time over the whole heap, follows
pointers
     and marks all chunks it can reach as used. unmarked chunks can be 
     considered as unreachable=unused and are collected/freed.
     
     an conservative GC needs to know (or guess) where pointers lay
around
     in the chunks to follow them. the Hans-Boehm-GC is able to do this 
     even without knowing the type infos. an disatwantage can be seen in 
     conjunction MT-realtime-applications, since the mark phase (when
walking
     through the heap), all threads have to stopped, but this should not
     be an problem if you're not really hanging on microseconds ...


if someone's interested, i'll do the most of the work with implementing
an GC (Hans-Boehm-GC) in glib/gtk, but i need some help with testing the 
build stuff (i wont touch this spooky automake) ...

~-n

--
 Enrico Weigelt    ==   meTUX IT services 
 software development, IT service, internet security solutions
 www:     http://www.metux.de/        phone:     +49 36207 519931
 email:   contact metux de            cellphone: +49 174 7066481



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]