Comments (4)
(日本の方とお見受けして日本語で回答します。)
私の環境ではリークらしき状況は確認できませんでした。
- Windows 10
- OpenCvSharp 4.9.0.20240106
- .NET 8 / .NET Framework 4.8
- Configuration: Debug/Release
一つだけ思い当るフシとして、以下のようなコードをお試しいただけますか。
for (long i = 0; i < 1000000000; i++)
{
double[] numbers = new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
using (Mat mat1 = Mat.FromArray(numbers))
using (InputArray ia1 = mat1)
{
Cv2.MinMaxLoc(ia1, out _, out _, out _, out _);
}
}
Cv2.XXX
メソッドたちの大半はInputArrayを取るようになっており、Matは暗黙にキャストされます。そうして作られるInputArrayオブジェクトが解放されない疑いはあります。(これは現行OpenCvSharpの一番の設計ミスと考えています)
from opencvsharp.
承知しました。
ご丁寧にありがとうございました。
from opencvsharp.
@shimat 様
早速お返事をいただきましてありがとうございます。
いただいたコードではメモリリークは発生しませんでしたので、おっしゃる通りなのではないかと思っております。
※ところでこの件とは関係ないかもしれませんが、下記のようなコード(Mat同士のDotやCross)でもメモリリークが発生するように見えます。
double[] arr1 = new double[3] { 0, 1, 2 };
double[] arr2 = new double[3] { 1, 2, 3 };
Mat mat1, mat2;
mat1 = Mat.FromArray(arr1);
mat2 = Mat.FromArray(arr2);
for (int i = 0; i < 100000000; i++)
{
// using (Mat val = mat1.Dot(mat2))
using (Mat val = mat1.Cross(mat2))
{
}
}
解決策をご存知でしたら、教えていただけますと幸いです。
また、別のissueを立てたほうが良いようでしたら再投稿いたします。
どうぞよろしくお願いいたします。
from opencvsharp.
DotやCrossは引数としてやはり InputArray
を取るため、同様の問題によるものと思います。
前のコメントのように using で全て取り扱うのが最も確実ですが、ほかに GC.Collect();
を頻繁に呼びまくる、という手もあります。簡易的な回避には良いかもしれません。
TorchSharp でのこちらのドキュメントは、だいたい事情はOpenCvSharpとも共通しており参考になるかもしれません。https://github.com/dotnet/TorchSharp/blob/main/docfx/articles/memory.md#technique-1-automatic-disposal-via-garbage-collection
from opencvsharp.
Related Issues (20)
- Where is Rect.Empty
- opencvshap4 no Extensions
- OpenCVSharp does not seem to work with Raspberry PI Camera Module 3
- opencvsharp4.9 + ubuntu 20.04 + NET6.0 + Docker Unable to load shared library 'OpenCvSharpExtern' or one of its dependencies HOT 1
- Convert Python code to C#
- Please add cv::dnn::imagesFromBlob() function
- How to build OpencvSharp for Windows with Gstreamer
- Different open cameras depending on the videoCaptureApi used
- Unable to load DLL 'OpenCvSharpExtern' or one of its dependencies HOT 1
- Compatibility of ver 4.9 with .Net 7.0
- Unable to detect if a image is blurred in few cases
- Errors while building OpenCVSharp from source HOT 22
- Max Score is infinity when using Mask for Template Matching HOT 2
- Linkage errors
- Avif encoder not available
- using opencvsharp for rotation/deskewing an Image is not rotating correctly HOT 1
- Need clear instructions on how to build opencvsharp with cuda to use gpu acceleration? HOT 11
- OOM Error HOT 1
- The type initializer for 'OpenCvSharp.Internal.NativeMethods' threw an exception
- Missing: Rotation estimation, Bundle adjustment, Levenberg Marquardt
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opencvsharp.