Git Product home page Git Product logo

Comments (11)

takuya-takeuchi avatar takuya-takeuchi commented on June 23, 2024

@GNUGradyn
Thank you for your good investigation.
I'll try to reproduce it,

from dlibdotnet.

takuya-takeuchi avatar takuya-takeuchi commented on June 23, 2024

NOTE
return of NativeMethods.array2d_row would not be disposed

from dlibdotnet.

takuya-takeuchi avatar takuya-takeuchi commented on June 23, 2024

Row should receive row in constructor and Row[index] use row and columns.
It should take a bit more time but does not use unnecesarry memory.

from dlibdotnet.

takuya-takeuchi avatar takuya-takeuchi commented on June 23, 2024

@GNUGradyn
Could you try the following code?

using DlibDotNet;

while (true)
{
    var test = new Array2D<RgbPixel>(10, 10);
    var row = test[0];
    row[0] = new RgbPixel
    {
        Red = 0,
        Green = 0,
        Blue = 0
    };
    row.Dispose();
    test.Dispose();
}

I think it works.

from dlibdotnet.

GNUGradyn avatar GNUGradyn commented on June 23, 2024

@takuya-takeuchi thank you for the quick response. This does work, but it feels like more of a workaround then a solution. When using an Array2D to store an image for facial recognition for an example, you would have to iterate thru and dispose every row when you are done (could be over 1000 rows for a higher resolution image). This could really start to add up if you are processing several frames to track a moving face, especially considering how often GC has to run when you are disposing of thousands of objects constantly.

If this is unavoidable, the library should at least do this automatically when you dispose the Array2D

from dlibdotnet.

GNUGradyn avatar GNUGradyn commented on June 23, 2024

I'm not really sure why but this solution also does not appear to work when creating/disposing rows in a loop

using DlibDotNet;

while (true)
{
    var test = new Array2D<RgbPixel>(10, 10);

    // Make some rows
    for (var i = 0; i < 10; i++)
    {
        var row = test[i];
        row[0] = new RgbPixel
        {
            Red = 0,
            Green = 0,
            Blue = 0
        };
    }
    
    // Delete all the new rows
    for (var j = 0; j < 10; j++)
    {
        var row = test[j];
        row.Dispose();
    }

    test.Dispose();
}

image

from dlibdotnet.

GNUGradyn avatar GNUGradyn commented on June 23, 2024

Matrix does not appear to have the same issue. Simply disposing of a Matrix works as you'd expect.

from dlibdotnet.

GNUGradyn avatar GNUGradyn commented on June 23, 2024

Using a Matrix appears to hit the garbage collector pretty hard, but not quite hard enough to create a GC pressure memory leak. This is an acceptable workaround
image

from dlibdotnet.

takuya-takeuchi avatar takuya-takeuchi commented on June 23, 2024

var row = test[i];

After execute this, Row is generated. Row has unmanaged object.
So this object shall be disposed every time.

If this is unavoidable, the library should at least do this automatically when you dispose the Array2D
Yes, I agree with you.
So I will fix Array[int][int].

Thanks.

from dlibdotnet.

takuya-takeuchi avatar takuya-takeuchi commented on June 23, 2024

@GNUGradyn
I fixed issue.

1. Keep current interface Array2D[int row]

This interface intents to let developer access to column value efficiently.
For example

using (var row = array[0])
{
    for (var c = 0; array.Columns; c++)
        Console.WriteLien(row[c]);
}

Row holds native pointer to improve performance.
So developer shall take care of usage of this property.

2. Add new interface Array2D[int row, int column]

For example

var test = new Array2D<RgbPixel>(10, 10);
test[0,0] = new RgbPixel
{
    Red = 0,
    Green = 0,
    Blue = 0
};

image

from dlibdotnet.

GNUGradyn avatar GNUGradyn commented on June 23, 2024

Thanks. I ended up just using a Matrix instead but I appreciate the fix

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.