c# - Memory Leak when Marshal.Copy -
c# - Memory Leak when Marshal.Copy -
i noticed programme leaking memory. used dotmemory find leak, , looks function causing leak:
private void loadbits() { // lock bitmap's bits. rectangle rect = new rectangle(0, 0, bm.width, bm.height); bmpdata = bm.lockbits(rect, system.drawing.imaging.imagelockmode.readwrite, bm.pixelformat); stride = bmpdata.stride; // address of first line. intptr ptr = bmpdata.scan0; // declare array hold bytes of bitmap. bytecount = math.abs(bmpdata.stride) * bm.height; bytes = new byte[bytecount]; // re-create rgb values array. system.runtime.interopservices.marshal.copy(ptr, bytes, 0, bytecount); }
and how unlock bits.
private void savebits() { // update stuff intptr ptr = bmpdata.scan0; system.runtime.interopservices.marshal.copy(bytes, 0, ptr, bytecount); bm.unlockbits(bmpdata); }
i implemented idisposable interface class. , phone call savebits there, if forget phone call savebits, gc should me. , yes, phone call bm.dispose() , set null in dispose method.
you need unlockbits()
when you're done.
c# memory memory-leaks
Comments
Post a Comment