Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Both Windows Phone/Xbox and Android lack support for generational garbage collection. This is frustrating for a lot of programmers. There seems to be a legitimate engineering reason to it, but I can't figure it out.

Current phones have more memory and probably better CPUs than the desktops/laptops running .NET 1.1 with generational GC back in 2001, and I can't think of any reasons that ARM processors would be worse at generational GC than x86 would. There's also less need for multitasking on phones and consoles, so there's relatively more free heap space.

So what gives?

Edit: A few points to clarify:

  • These platforms use garbage collection for apps exclusively, so my question isn't about why GC isn't supported; my question is about why generational garbage collection isn't.
  • The reason that people are frustrated about the lack of generational GC is that non-genrational GC is extremely inefficient. (That means that battery life isn't the reason.)
  • I do believe that there's an honest technical reason for the lack of generational GC support. This isn't a rhetorical question.
share|improve this question
    
Windows phone (the current generation) does have garbage collection. It only runs when the device is low on memory msdn.microsoft.com/en-us/library/gg490770.aspx –  Tom Squires Feb 8 '12 at 0:17
    
@TomSquires The GC on WP7 runs once every 1MB of allocations, actually. I think you might be thinking about the task manager kerning old processes. –  Rei Miyasaka Feb 8 '12 at 0:23

3 Answers 3

I think the biggest problem is the battery life. Garbage collection is a developer convenience bought at the price of additional CPU cycles on user's computer. When your CPU is plugged in (desktop) or has a relatively large battery (laptop), your users are more willing to pay for developers' convenience with the additional energy consumed by CPU while doing garbage collection. When the battery is relatively small, the users may not be as generous. They may want that additional bar for themselves - perhaps to talk to their friends, or to kill a few extra pigs in a deadly encounter with angry birds.

No matter what users' reasons are, OS developers do not want to form a perception that the devices running their OS drain battery faster than ones running their competitor's OS. So they buy better perception of their devices' expected battery life time at the price of developers' convenience: to them, your pain is no big deal, as long as the users are happy with the devices.

share|improve this answer
1  
Generational GC is much more efficient in most cases, actually, so you'd think that it'd reduce the number of clock cycles. It also doesn't explain why something like Xbox doesn't have generational GC, because Xboxes are plugged in. –  Rei Miyasaka Feb 7 '12 at 23:03
    
Well, that's what I heard on Stack Overflow. I do not know much about XBox-es, though. –  dasblinkenlight Feb 7 '12 at 23:09
1  
That still doesn't answer the question. Even if garbage collection used more power than explicit allocation (which is highly debatable -- and I won't get into it), the question isn't if/why explicit allocation is better than GC on mobile, it's if/why non-generational GC is better than generational GC on mobile. –  Rei Miyasaka Feb 7 '12 at 23:17
1  
@Rei: Games typically require everything to be deterministic; at least, they need predictable performance. A few nanoseconds wasted here and a few nanoseconds wasted there - at unpredictable times - can screw up a game experience. Generational garbage collectors are unpredictable. –  Ant Feb 7 '12 at 23:17
2  
@djacobson I don't think that's true. Like I said in the question, if it were just Microsoft's platforms neglecting generational GC, then it'd probably just be a logistical/bureaucratic reason, and I wouldn't bother asking. But Android suffers the same problem too, so it's likely a technical reason, which means that someone on P.SE might have a definitive answer. –  Rei Miyasaka Feb 7 '12 at 23:45

There is some additional cost to generational garbage collection.

The generational collector needs to be able to find out when older objects point to newer objects. We can't trace through the older object to find these cases because that would defeat the purpose of generational collection. Instead, we somehow need to detect when this happens and make note of it for the collection phase. Regardless of how you are going to do that, it'll add some overhead to the collection process.

On a desktop system, your operating system is busily doing all kinds of things with memory behind the scenes. It supports features like sharing pages between processes, writing unused pages to disk, providing memory mapping between processes, etc. My understanding is that some of the functionality used there makes it possible to more efficiently track pointers being changed. The operation is already worrying about what you are changing in memory, so using that information for new purposes isn't a problem.

I suspect that mobile systems aren't doing all the same stuff behind the scenes. As a result, they don't have the same level of information that a desktop would have. In consequence, the overhead involved in implementing a general collection is higher and less likely to be worth it.

share|improve this answer
    
Taking maximal advantage of GC generations requires the use of write fences to detect when older-generation objects are written. On the other hand, even if the "mark" portion of the GC couldn't benefit from generations, I would think one could still improve performance by only moving things in newer generations (actually, doing the "tag" phase on older generations as well as newer could be useful if it allowed one to know how much reclaimable memory existed in each generation). –  supercat Jul 10 '12 at 19:11

My best guess would be that it's not a technical reason, but that the developers for those phone platforms simply haven't put in the effort yet. I know it's not the answer you're hoping for, but if you've done any mobile development you've probably noticed there is a lot of low hanging fruit. They probably simply haven't had the time to write multiple GC implementations, fine tune them all, and select the one that does best. Why would anyone spend time reinventing the wheel when they could instead release new, flashy, poorly-thought-out APIs? ;)

FWIW, and as confirmation of my theory, Android's new runtime (ART) does have a generational GC and they're planning to have a compacting GC in the future.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.