2

I currently use a NDA-library (non commercial) which has zero documentation and uses EMGU. Here is a example for my Question:

public void example()
{
     Image<Gray,byte> exp = new Image<Gray,byte>(128,128);
     foo(exp);
     exp.Dispose();
}

public bool foo(Image<Gray,byte> bar)
{
     //magic here
     //bar.Dispose() ??
     return true;
}

When I pass an EMGU-Image from one function to another, do i have to call .Dispose() in the called function, too? Or is it sufficient to call it in the callee?

theB
  • 6,450
  • 1
  • 28
  • 38
bam
  • 954
  • 8
  • 26
  • 1
    Good question, but it has already been answered at length. The standard rule of thumb is, if you *create* it, you're responsible for *disposing* it (unless there is an agreed-upon transfer of ownership). For more details, also look up how parameters are passed. Objects like this are passed by reference in C#, so you're not making a copy of the object. – Cody Gray - on strike Jun 29 '16 at 18:48
  • Note also that you should use the `using` keyword to ensure that exp.Dispose() is called, even if an exception is thrown. – Eric J. Jun 29 '16 at 18:50
  • @CodyGray oh snap! But I swear I used the search multiple times. But maybe I just wasn't able to search it with the right words. Thanks for your answer (comment) and the Link! – bam Jun 29 '16 at 19:15

1 Answers1

0

It's better to only call Dispose() once. However it should be ok to call it more than once, if the Dispose() method was written in the "normal fashion."

tsandy
  • 911
  • 4
  • 10