exit() is your friend

I was just reading the Google Chrome cartoon book
(an interesting way of presenting designs). One of the things they
talked about was how having browser tabs in separate process helps with
memory consumption because memory gets cleaned up with the process
exits. Otherwise, the constant malloc/free cycle ends up with memory
fragmentation that is hard to get rid of.

That brought back some
memories. In my early work on a code generator, I used the same
philosophy. I created a pretty big object model in memory after I
parsed the input, but I never implemented any of the destructors and
never called delete. Didn’t need to. It was a short lived process and
the call to exit() at the end freed up all the memory anyway. And it’s
pretty fast! Lot faster than calling delete for each object I created.

Continue Reading ››