about dispose? RRS feed

  • Question

  • I use Mat of OpencvSharp.

    for example, My code :

    Mat Computer(Mat m,double ex,double add,double mul){

         using(Mat p = m.Power(ex)) {

               using(Mat mu = p.Mul(mul){

                   Mat ad = mu.Add(add);

                   return ad;




    I wish Code like this follow:


    Mat Computer(Mat m,double ex,double add,double mul){

        return m.Power(ex).Mul(mul).Add(add);


    but this code raises one question:
    1、 raise memory out because of some temp variant can't dispose immediately and.

    How can I do?

    • Edited by twtkss Tuesday, April 30, 2019 8:53 AM
    • Moved by CoolDadTx Tuesday, April 30, 2019 4:03 PM Third party product
    Tuesday, April 30, 2019 8:23 AM

All replies

  • You should ask this question here since this is a non Microsoft library.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Tuesday, April 30, 2019 9:36 AM
  • my question is a opencvlib's question, but this question is commonly  in C# language.

    i will design  a class and it likes Mat's chain calling :

    for examle:


    every calling constructor one temp variant.

    i have any way to control the memory dispose except "using",but it likes

    using(var temp1= objec1.method1())

         using(var temp2=temp1.mehtod2(){




    The code looks very long and ugly.

    temp variants can auto release if i use C++ lanuage.

    how design in C# language ?  can't ?

    • Edited by twtkss Thursday, May 2, 2019 8:36 AM
    Thursday, May 2, 2019 8:32 AM