title: Dispose of an object referenced via pointer in C#
body: <p>I am using a C# wrapper to an API which is providing image data from a camera.</p>
  
  <p>I have a class which contains data for each frame received, and I would like to implement a dispose method to run once the frame data has been processed. The problem is the primary object I wish to dispose of (an image buffer) is only accessible via a pointer.</p>
  
  <p>I don't know if this is even necessary in C#. I know that in C++ I would have to do something with it to prevent a memory leak, however I don't know much about how pointers work in C# in terms of garbage collection. As it is, the program works okay, but the memory usage does jump around a lot more than I'd like it to. I've found that proper disposal of certain objects has given much more consistent memory usage compared to relying on what I assume to be finalizers being automatically run, such as when disposing of an existing image on an image box before setting a new one. I'd like to try something similar here if possible.</p>
  
  <p>Potentially important: the data the pointer points to is processed by unsafe code, which creates two new pointers to the object (one as UInt16* and another as byte*). Both of these pointers only exist within the scope of the unsafe routine but I'm not sure if this interferes with GC in some way.</p>
  
  <p>Any advice, recommendations appreciated. Thanks</p>
  
  <p><strong>Edit</strong>: I am receiving the frame data via callback from an external API.</p>