Git Product home page Git Product logo

Comments (5)

takuya-takeuchi avatar takuya-takeuchi commented on May 26, 2024

That's right.
For now, array class will not be released.

DLLEXPORT void array_delete(void* obj)
{
    // dlib::array is template type.
    // Ex. dlib::array<dlib::matrix<float, 31, 1>> does NOT equal to dlib::array<dlib::matrix<float>>
    // Template argument is decided in compile time rather than runtime.
    // So we can not specify template argument as variable.
    // In other words, we have to call delete for void* because we do not known exact type.
    // Unfortunately, dlib::array implement destructor.
    // What should we do?
    delete obj;
}

However, I probably should check type and delete it for except for template types looks like dlib::array<dlib::matrix<float, 31, 1>>.

from dlibdotnet.

akade avatar akade commented on May 26, 2024

I fixed it for me by modifying the wrapper:

` protected override void DisposeUnmanaged()
{
base.DisposeUnmanaged();

        switch (_ItemType)
        {
            case ItemTypes.PixelType:
                {
                    Dlib.Native.array_delete(this.NativePtr);
                }
                break;
            case ItemTypes.Array2D:
                {
                    var type = this._ArrayElementType.ToNativeArray2DType();
                    Dlib.Native.array_array2d_delete(type, this.NativePtr);
                }
                break;
            case ItemTypes.Matrix:
                {
                    throw new NotSupportedException("Memory leak");
                }
                break;
            default:
                throw new ArgumentOutOfRangeException();
        }
    }`

and adding the following native method:

DLLEXPORT void array_array2d_delete(array2d_type type, void* obj) { switch (type) { case array2d_type::UInt8: delete ((dlib::array<array2d<uint8_t>>*)obj); break; case array2d_type::UInt16: delete ((dlib::array<array2d<uint16_t>>*)obj); break; case array2d_type::Int16: delete ((dlib::array<array2d<int16_t>>*)obj); break; case array2d_type::Int32: delete ((dlib::array<array2d<int32_t>>*)obj); break; case array2d_type::Float: delete ((dlib::array<array2d<float>>*)obj); break; case array2d_type::Double: delete ((dlib::array<array2d<double>>*)obj); break; case array2d_type::RgbPixel: delete ((dlib::array<array2d<rgb_pixel>>*)obj); break; case array2d_type::HsiPixel: delete ((dlib::array<array2d<hsi_pixel>>*)obj); break; case array2d_type::RgbAlphaPixel: delete ((dlib::array<array2d<rgb_alpha_pixel>>*)obj); break; } }
I also did that for the matrix class, where you already had this code but as comment because of some special fixed size matrix templates. I had no issueswith it and I think at least the above array code is save.
And it fixed my memory leak. In case you want to integrate that.

from dlibdotnet.

takuya-takeuchi avatar takuya-takeuchi commented on May 26, 2024

Thank you so much!!
Please give me moment to check your codes.
Unfortunately, I am busy here recently, so I can not do any coding :(

from dlibdotnet.

takuya-takeuchi avatar takuya-takeuchi commented on May 26, 2024

OK, It should be ok.
Could you send PR if you can?
After merge, I add code to release array.

from dlibdotnet.

takuya-takeuchi avatar takuya-takeuchi commented on May 26, 2024

Fix by 5c34efa

from dlibdotnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.