Allan McLemore
10/19/2004 8:04:00 PM
Hi Ken
One way you can test this is simply call the garbage collector yourself
after *not* using each image, if you simply aquire each JPG and turn it into
a .NET image, then let it fall out of scope and call GC.Collect you should
be able to see if that is the problem. Just an idea :-)
Nick.
"Ken Varn" <nospam> wrote in message
news:e8bbRNhtEHA.2788@TK2MSFTNGP09.phx.gbl...
> At this point, I am not sure if I have a memory leak or not. The jury is
> still out on that right now. I just wanted to make sure make sure that
> the
> Dispose method call was not required to free up the bitmap resources. The
> "memory leak" may have been the fact that the GC had not collected the
> bitmap memory yet and I could have assumed a leak.
>
> --
> -----------------------------------
> Ken Varn
> Senior Software Engineer
> Diebold Inc.
>
> EmailID = varnk
> Domain = Diebold.com
> -----------------------------------
> "Nak" <a@a.com> wrote in message
> news:%23NgVt5dtEHA.1276@TK2MSFTNGP12.phx.gbl...
>> Hi Ken,
>>
>> >I have an application that uses a PictureBox to display real-time video
>> >that
>> > is captured from a JPEG video acquisition card. I basically get a JPEG
>> > image buffer from the card that I convert to a .NET Bitmap object. I
> then
>> > assign a clone of the Bitmap object to the Image property of the
>> > PictureBox.
>> > This is done at about 30 images per second. The PictureBox displays
>> > the
>> > consecutive images correctly. One thing that I am concerned with is
> that
>> > I
>> > think that I am seeing a memory leak and I am not sure how to get
> around.
>>
>> Assigning an image to an picture box should cause no memory leak at
> all,
>> the image object is disposed of when it has no references and falls out
>> of
>> scope, as with almost all objects in .NET. You might find that your
> memory
>> leak is coming from elsewhere, possibly in the code that is converting
>> the
>> image to a .NET bitmap object, have you tried simply letting the objects
>> fall out of scope instead of assigning them to the picturebox to see if
> your
>> memory leak still occurs?
>>
>> > Each time I assign the image to the PictureBox I do this by calling the
>> > Clone method. of the Image and assign it to the PictureBox.Image
>> > property.
>> > The part that I am confused about is should I call the Dispose method
>> > of
>> > the
>> > Image assigned to the PictureBox before I assign a new Image object to
> it
>> > or
>> > will the Image object release its resources when it is garbage
> collected?
>>
>> You shouldn't need to dispose of the image object, the Clone method
>> is
>> used to create a new object with the same data in, so if the original
> object
>> changes your "clone" wont (that is my understanding anyway). How is your
>> JPEG getting converted to a .NET bitmap? Are you getting the image from
>> a
>> COM library or is it all .NET code?
>>
>> I had some code recently which obtained an image via COM and
>> converted
>> it to .NET, I found a memory leak in the code as it did not release all
>> of
>> the COM objects. I originally thought it might be the cloning of the
> image,
>> but I don't think it is possible as long as you aren't storing all of the
>> objects anywhere else so that they never fall out of scope? Anyway, hope
>> this helps.
>>
>> Nick.
>>
>>
>
>