For the past few months we have been fighting against various memory problems. Preventing memory leaks with careful coding strategies and maintaining memory safety in our mixed language environment has become a show stopper. We observe that many of the memory problems are caused by sharing data between M3 and C modules. In particular, memory safety may be breached if passing a traced reference to C code without immobilizing the traced data. For example, C code accessing data that has been moved by the collector is memory unsafe and violates the correctness of the system. Further, the allocation of untraced memory may be unrecoverable if passed to untrusted extension, or may cause a memory leak if not deallocated. It is critical that we can ensure both memory safety and prevent memory leaks to maintain system stability.
What follows is a list of things that one should be aware of to maintain memory safety and prevent leaks. There are several cases that can introduce memory problems: