title: Memory / heap management across DLLs
body: <p>Although it seems to be a very common issue, I did not harvest much information: How can I create a safe interface between DLL boundaries regarding memory alloction?</p>
  
  <p>It is quite well-known that </p>
  
  <pre><code>// in DLL a
  DLLEXPORT MyObject* getObject() { return new MyObject(); }
  // in DLL b 
  MyObject *o = getObject();
  delete o;
  </code></pre>
  
  <p>might certainly lead to crashes. 
  But since interactions like the one above are - as I dare say - not uncommon, there has to be a way to ensure safe memory allocation.</p>
  
  <p>Of course, one could provide</p>
  
  <pre><code>// in DLL a
  DLLEXPORT void deleteObject(MyObject* o) { delete o; }
  </code></pre>
  
  <p>but maybe there are better ways (e.g. smart_ptr?). I read about using custom allocators when dealing with STL containers as well.</p>
  
  <p>So my inquiry is more about <strong><em>general pointers to articles and/or literature dealing with this topic</em></strong>. Are there special fallacies to look out for (exception handling?) and is this problem limited to only DLLs or are UNIX shared objects "inflicted" too?</p>