Private bytes memory leak in code

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I am debugging one memory leak problem and found the code which is creating this leak. Below is the part of the code,
<pre class="prettyprint" style=" byte[] computedData = new byte[736 * 240];
for (int i = 0; i < 240; i++)
{
Array.Copy(data, i * 768, computedData, i * 736, 736);
}
data = null;

System.Drawing.Bitmap bitmap = ObjectConverter.PaintRawBitmapToImageControl(computedData, 240, 736);
BitmapSource source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
BitmapFrame frame = BitmapFrame.Create(source);

computedData = null;

return frame;[/code]
In above code PaintRawBitmapToImageControl manipulates the byte array and give me the Bitmap object.
The problem lies in the large byte[] allocated. Actually it is truncating some unneeded part from the stream.
I checked the PerfMon and it is continuously increasing the Private Byte counter. But the Large Object Heap size is not increasing. If I comment the array allocation and the for loop it works fine (i.e. Private bytes doesnt increase).<br/>

I suspect that the byte array is not freed properly but unable to find why. How can I free it?
I appreciate your help in this regard.




<
Regards, Jignesh
<br/>
<br/>

View the full article
 
Back
Top