Garbage Collection: The Magic Number is 6

I read a fascinating article recently on why mobile apps are so slow – the article is well worth the peruse as to why JavaScript apps will never keep up to C/C++ (note this also affects most interpreted languages like Python, Ruby, Java, etc).

But the main point I remembered is the magic number for garbage collection: Six times the used memory. Or to put it another way, as long as you keep your program’s memory usage under 1/6 of available memory, life is good (I’m referring to GC-managed memory of course).

But go under that – especially under 4x (or 1/4) – and it gets very bad. In fact, the function for it is exponential, and under 1/6 memory the curve starts to climb fast. In the cases he mentioned in his post, some tests took 10-15 times as long to run when GC was used versus regular memory management.

This isn’t surprising of course: I programmed the Commodore 64 which had string garbage collection, and you soon got a feel for how many strings you could handle. Too many, and the computer abruptly halted while it cleaned them up. Today, however, most programmers on desktops never hit a performance issue, since 1/6th the memory is a LOT of strings or other data. But on small devices that 1/6 comes up quickly…

Morale of the story: Enjoy your Java, but never forget your malloc() and new[] – and be sure you remember ‘6’ while you craft your next Java app…

Arduino Starter kit **ARDUINO NOT INCLUDED**
$0.99 (0 Bids)
End Date: Tuesday Feb-27-2018 16:28:15 PST
Bid now | Add to watch list
Arduino Parts *arduino not included*
$0.99 (0 Bids)
End Date: Tuesday Feb-27-2018 16:26:51 PST
Bid now | Add to watch list
Pro UNO R3 Board Starter 1602 LCD Kit for Arduino Keypad Servo compass Gyroscope
$10.99 (0 Bids)
End Date: Friday Feb-23-2018 18:03:46 PST
Bid now | Add to watch list

Leave a Reply

Your email address will not be published. Required fields are marked *