Re: Confusion about Image object and PictureBox usage.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Nak (a_at_a.com)
Date: 10/19/04


Date: Tue, 19 Oct 2004 21:04:03 +0100

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.
>>
>>
>
>



Relevant Pages

  • Re: Confusion about Image object and PictureBox usage.
    ... I am not sure if I have a memory leak or not. ... >>I have an application that uses a PictureBox to display real-time video ... >> image buffer from the card that I convert to a .NET Bitmap object. ... You shouldn't need to dispose of the image object, the Clone method is ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Memory leak in ruby code
    ... Even when it's out of scope, ... leaks in ruby code is still not very clear to me. ... I'd like to see if someone can point me to an example of memory leak ... Dont judge those who try and fail, judge those who fail to try.. ...
    (comp.lang.ruby)
  • Re: Psuedo-dynamic allocation?
    ... exist after the code that created them goes out of scope: ... Memory leak! ... home dot pacbell dot net slant earnur slant ...
    (comp.lang.cpp)
  • Re: Confusion about Image object and PictureBox usage.
    ... I basically get a JPEG ... > image buffer from the card that I convert to a .NET Bitmap object. ... The PictureBox displays the ... > think that I am seeing a memory leak and I am not sure how to get around. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: char*
    ... goes out of scope, not that it is. ... would this cause a memory leak? ... So running foo() 1000 time would create 1000 string literal ... So the second time foo() is called the string literal constructed ...
    (comp.lang.c)