There's three trivial steps to solve ALL of this: a) don't manually delete things, at all b) store pointers that have been passed to C functions where the GC can see them. c) For memory that's explicitly supposed to _belong_ to the C functions, use cstdlib malloc. If you keep to these three points, things become very simple.