I am wondering if in the given scenario below, any manual Bitmap dispose action need take place. Let's say I have two Bitmaps global to my WinForm, A and B. Lets say I want to do some transform/blend operation on their respective images, but want to do so on copies. I aim to call the transform function (Bitmap Transform(Bitmap first, Bitmap second)
) similarly to this:
var newB = Transform( ( Bitmap )A.Clone(), ( Bitmap )B.Clone() ).
When done in Transform
, do I dispose of the A
and B
copies within transform? Do I copy before the invocation and then dispose after the return? Since these references are absolutely lost after the Transform
return, can I trust the GC?
-EDIT_ ADDING COMMENT FROM BELOW_-
As for the potential duplication, I saw that post, but it lacked any examples of using arguments created at the time of invocation. I wanted to know if the passed objects have no home in the invocation scope, if there was a way to dispose, if a dispose was necessary, or if a home must be given to properly handle disposal. It seems as though creating disposable objects with no ability to dispose of them in the creation scope is not recommended from what I gather here. –
Additionally, I can confirm that Martin's solution is effective, though doing the clones in the body of transform proved the most organized and clean. Only one of the clones needed to be disposed, as I used one as the object referenced in the return. Lastly, the clone was necessary, as any picturebox image refresh throws an exception if its image is in read bitlock,as is necessary for the transform.thanks for the help everyone