My head, perhaps, my gut, no. Give me some time to brush up my Java skills (been busy with C++ the last four years), and I show you a memory leak in about 20-30 lines of Java. If I introduce complexity (GC) to solve a problem (memory management being bug-prone), it better solve the problem for sure or it isn't worth the effort in my book.Colonel Kernel wrote: Your gut needs to learn about more GC algorithms.
But that's just me.
As for the Wiki page "Garbage Collection", I have a serious complaint with this paragraph:
What's described here - keeping free blocks in a single list and scanning that on an allocation - is what I've done as a malloc() placeholder in PDCLib with 113 lines of code. Comparing a compacting GC with a 100-line malloc() placeholder is hardly fair.One of the major advantages of a compacting collector is that it makes allocating from the heap extremely fast and scalable to multiprocessor systems. All you have to do to allocate a new object is to increment a "top-of-heap" pointer and initialize a few fields, which can be done in constant time. Compare this to a traditional implementation of malloc(), which may need to scan many entries in the free list in order to find a block large enough to satisfy the request. In the worst case, this takes linear time based on the length of the free list. Consider that in a multiprocessor system, holding a global heap lock while scanning the free list is not a very good idea.
I don't know about the author's definition of "traditional", but "normal" malloc() implementations hold lists of similar-sized free blocks, and satisfy larger requests using [tt]mmap()[/tt], which means the memory can be returned to the system without any memory-copying.
I am willing to admit that GC has its uses, but I don't agree to biased... well, "propaganda" for lack of a better word.
And then there's the issue of C/C++ allowing pointers, and pointer arithmetics. Unless you want to write your kernel in C#, VB, Java or Python, you simply replace the issue of remembering to do proper memory cleanups with the issue of remembering not to do The Bad Thing (tm) with pointers - which is probably rather hard to avoid in kernel space.
Bottom line, yes, GC in kernel space is most likely possible. But whether it is worth the effort is in the eyes of the beholder. Just like writing an OS in Pascal or going to lengths to make "pure" microkernels. Let's provide NPOV information, instead of trying to make [tt]malloc()[/tt] look worse than it is.