title: How to handle UnsafeMutablePointer correctly
body: <p>I am a little confused. When do I have to call free and when destroy/dealloc? I am working on a short code snippet learning core audio. I thought if I call     <code>UnsafeMutablePointer&lt;Type&gt;.alloc(size)</code> then I should call <code>destroy</code> &amp; <code>dealloc</code>.
  But if I use <code>malloc()</code> or <code>calloc()</code> I am supposed to call <code>free()</code>.</p>
  
  <p>In this example from Learning Core Audio the following code snippet makes me wonder:</p>
  
  <pre><code>var asbds = UnsafeMutablePointer&lt;AudioStreamBasicDescription&gt;.alloc(Int(infoSize))
  audioErr = AudioFileGetGlobalInfo(kAudioFileGlobalInfo_AvailableStreamDescriptionsForFormat,
                                UInt32(sizeof(fileTypeAndFormat.dynamicType)), &amp;fileTypeAndFormat,
                                &amp;infoSize, asbds)
  </code></pre>
  
  <p>Here I use <code>alloc</code>. To free up memory <code>free</code>is called.</p>
  
  <pre><code>free(asbds)
  </code></pre>
  
  <p>But why not</p>
  
  <pre><code>asbds.destroy(Int(infoSize))
  asbds.dealloc(Int(infoSize))
  </code></pre>
  
  <p>which I would expect following the rule.</p>
  
  <p>I would appreciate any help, because this makes my head spin. The documentation says I am responsible for destroying and dealloc so that part is clear, but in which way?</p>