C#内存管理问题
c#调用c++动态库得到一张图像:
imgBuffer = Marshal.AllocHGlobal(imageProp.ImgHeight * imageProp.ImgWidth * Marshal.SizeOf(typeof(ushort)));
CDetManager.Acquisition(imgBuffer, nDET);
然后将此图处理,并显示:
byte[] data = new byte[imgp.ImgHeight * imgp.ImgWidth * 2];
Marshal.Copy(imgBuffer, data, 0, imgp.ImgHeight * imgp.ImgWidth * 2);
但是在new byte[]的时候,调试状态总是崩溃,提示OutOfMemoryException,但是从exe执行该程序,一切正常。
请问该怎么解决需要释放内存吗?