Last active
August 29, 2015 14:17
-
-
Save 0V/4f97dbfc985acf54fa2a to your computer and use it in GitHub Desktop.
メモリリークする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using OpenCvSharp; | |
// using OpenCvSharp.CPlusPlus; | |
// リソースを解放しないとメモリリークする | |
public static void CannotAllocateMemoryMethod(int cameraId) | |
{ | |
using (var capture = new VideoCapture(cameraId)) | |
{ | |
var srcMat = new Mat(); | |
while (Cv2.WaitKey(1) < 0) | |
{ | |
capture.Read(srcMat); | |
var grayMat = srcMat.CvtColor(ColorConversion.BgrToGray); | |
var binaryMat = grayMat.Threshold(100, 255, ThresholdType.Binary); | |
var dstMat = binaryMat.CvtColor(ColorConversion.GrayToBgr); | |
Cv2.ImShow("src", srcMat); | |
Cv2.ImShow("dst", dstMat); | |
// grayMat.Dispose(); | |
// binaryMat.Dispose(); | |
// dstMat.Dispose(); | |
} | |
} | |
} | |
// メソッドチェーンしてもメモリリークする | |
public static void CannotAllocateMemoryMethod2(int cameraId) | |
{ | |
using (var capture = new VideoCapture(cameraId)) | |
{ | |
var srcMat = new Mat(); | |
while (Cv2.WaitKey(1) < 0) | |
{ | |
capture.Read(srcMat); | |
srcMat.CvtColor(ColorConversion.BgrToGray) | |
.Threshold(100, 255, ThresholdType.Binary) | |
.CvtColor(ColorConversion.GrayToBgr); | |
Cv2.ImShow("src", srcMat); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment