In order to move the nsMemory static class into the xpcom glue library, we needed to define new functionality in xpcom.
(Note that this is orthoganal to which allocator clients use - malloc verse nsMemory... see bug 75620 if you are interested) The first problem that we needed to deal with was that the nsMemory class, which is a helper wrapper around the nsIMemory interface, is called before the service manager is completely initialized. To allow the glue library to work, we added NS_GetMemoryManager(). This C-style API will allow anyone to get the nsIMemory interface from xpcom. You must call this only after NS_InitXPCOM2(). The second problem that we faced was that we wanted to cache our reference to the nsIMemory interface inside our glue library. The problem was that, we didn't have a way to know when xpcom completely shutdown. There is the nsIObserverService which xpcom uses to notify of xpcom-shutdown, but this is way to early as many component will want to free memory using nsMemory during their observance of shutdown. We couldn't leak this object, so we had to think of some way to callback clients at a very low level. We adopted a mechnicism similar to libc where by a client can add a exit routine which will be called right before xpcom is totally shutdown. Unlike libc, there is no priority and callback order will be undefined. You can see new proposed patch in bug number 112262. As always, comments welcome, Doug Turner
