Bitmap ?!

  • Thread starter Thread starter Lloyd Dupont
  • Start date Start date
L

Lloyd Dupont

in my program I could edit picture and import them from a file.
we test recently from a 143Kb jpg and I have weird problem.

in the program it's stored as a byte[] data;
when the user want to see it I create the picture with

Bitmap b = new Bitmap(new MemoryStream(data));

what's really weird is if I look at the picture many times in a row
sometimes the bitmap creation failed.

any ideas ? tips ? experiences ?
 
Lloyd,

Are you forgetting to dispose of bitmaps you no longer need?

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 
mmhh....
well I might...
but I was told to trust the garbage collector !

anyway that's a good remark I will try to see if there is a possibility to
put some Dispose() somewhere .. (I mean the application was not thought this
way..)

just a question (which would ease my pain) could reuse a bitmap once it has
been disposed (explicitly by a call to Dispose()) ? or no ?

--
ihookdb
Get your data mobile
http://www.ihookdb.com


"Ilya Tumanov [MS]" said:
Lloyd,

Are you forgetting to dispose of bitmaps you no longer need?

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "Lloyd Dupont" <net.galador@ld>
Subject: Bitmap ?!
Date: Fri, 30 Apr 2004 09:40:58 +1000
Lines: 20
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: adsl-11-233.swiftdsl.com.au 218.214.11.233
Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10
phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.framework.compactframework:52090
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

in my program I could edit picture and import them from a file.
we test recently from a 143Kb jpg and I have weird problem.

in the program it's stored as a byte[] data;
when the user want to see it I create the picture with

Bitmap b = new Bitmap(new MemoryStream(data));

what's really weird is if I look at the picture many times in a row
sometimes the bitmap creation failed.

any ideas ? tips ? experiences ?
 
Consider this:
instead
pictureBox1.Image = new Bitmap(...)
use
try
{
pictureBox1.Image.Dispose()
}
catch( ObjectDisposedException)
{
}
pictureBox1.Image = new Bitmap(...)


And yes - GC will eventually take care of bimtaps but each bitmap eats a lot
of GDI memory - much more than it does managed memory, so not calling
Dispose causes GDI memory to be exhausted long before there is any need for
GC to kick in. Thiis applies to all objects that have unmanaged data
attached - Events, Files, Brushes, Grapics (Graphicses?) etc


--
Alex Feinman
---
Visit http://www.opennetcf.org
Lloyd Dupont said:
mmhh....
well I might...
but I was told to trust the garbage collector !

anyway that's a good remark I will try to see if there is a possibility to
put some Dispose() somewhere .. (I mean the application was not thought this
way..)

just a question (which would ease my pain) could reuse a bitmap once it has
been disposed (explicitly by a call to Dispose()) ? or no ?

--
ihookdb
Get your data mobile
http://www.ihookdb.com


"Ilya Tumanov [MS]" said:
Lloyd,

Are you forgetting to dispose of bitmaps you no longer need?

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "Lloyd Dupont" <net.galador@ld>
Subject: Bitmap ?!
Date: Fri, 30 Apr 2004 09:40:58 +1000
Lines: 20
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: adsl-11-233.swiftdsl.com.au 218.214.11.233
Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10
phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.framework.compactframework:52090
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

in my program I could edit picture and import them from a file.
we test recently from a 143Kb jpg and I have weird problem.

in the program it's stored as a byte[] data;
when the user want to see it I create the picture with

Bitmap b = new Bitmap(new MemoryStream(data));

what's really weird is if I look at the picture many times in a row
sometimes the bitmap creation failed.

any ideas ? tips ? experiences ?
 
Garbage collector works just fine for managed objects.
However, some objects (e.g. Bitmap) might allocate native recourses and you
need to call Dispose() to free them.
Please see description of IDisposible interface for details.

As to reusing disposed Bitmap, I can not see how you can do it.
There's no method to get new image into the bitmap (disposed or not), so
you need to create a new on.
Before you do, dispose of the old one:

Bitmap b;

...

if (null != b) b.Dispose();
b = new Bitmap(...);

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "Lloyd Dupont" <net.galador@ld>
References: <[email protected]>
Subject: Re: Bitmap ?!
Date: Fri, 30 Apr 2004 10:34:21 +1000
Lines: 74
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
Message-ID: <#[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: adsl-11-233.swiftdsl.com.au 218.214.11.233
Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11
..phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.framework.compactframework:52095
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

mmhh....
well I might...
but I was told to trust the garbage collector !

anyway that's a good remark I will try to see if there is a possibility to
put some Dispose() somewhere .. (I mean the application was not thought this
way..)

just a question (which would ease my pain) could reuse a bitmap once it has
been disposed (explicitly by a call to Dispose()) ? or no ?

--
ihookdb
Get your data mobile
http://www.ihookdb.com


"Ilya Tumanov [MS]" said:
Lloyd,

Are you forgetting to dispose of bitmaps you no longer need?

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "Lloyd Dupont" <net.galador@ld>
Subject: Bitmap ?!
Date: Fri, 30 Apr 2004 09:40:58 +1000
Lines: 20
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: adsl-11-233.swiftdsl.com.au 218.214.11.233
Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10
phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.framework.compactframework:52090
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

in my program I could edit picture and import them from a file.
we test recently from a 143Kb jpg and I have weird problem.

in the program it's stored as a byte[] data;
when the user want to see it I create the picture with

Bitmap b = new Bitmap(new MemoryStream(data));

what's really weird is if I look at the picture many times in a row
sometimes the bitmap creation failed.

any ideas ? tips ? experiences ?
 
done !

--
ihookdb
Get your data mobile
http://www.ihookdb.com


Alex Feinman said:
Consider this:
instead
pictureBox1.Image = new Bitmap(...)
use
try
{
pictureBox1.Image.Dispose()
}
catch( ObjectDisposedException)
{
}
pictureBox1.Image = new Bitmap(...)


And yes - GC will eventually take care of bimtaps but each bitmap eats a lot
of GDI memory - much more than it does managed memory, so not calling
Dispose causes GDI memory to be exhausted long before there is any need for
GC to kick in. Thiis applies to all objects that have unmanaged data
attached - Events, Files, Brushes, Grapics (Graphicses?) etc


--
Alex Feinman
---
Visit http://www.opennetcf.org
Lloyd Dupont said:
mmhh....
well I might...
but I was told to trust the garbage collector !

anyway that's a good remark I will try to see if there is a possibility to
put some Dispose() somewhere .. (I mean the application was not thought this
way..)

just a question (which would ease my pain) could reuse a bitmap once it has
been disposed (explicitly by a call to Dispose()) ? or no ?

--
ihookdb
Get your data mobile
http://www.ihookdb.com


"Ilya Tumanov [MS]" said:
Lloyd,

Are you forgetting to dispose of bitmaps you no longer need?

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
From: "Lloyd Dupont" <net.galador@ld>
Subject: Bitmap ?!
Date: Fri, 30 Apr 2004 09:40:58 +1000
Lines: 20
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: adsl-11-233.swiftdsl.com.au 218.214.11.233
Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10
phx.gbl
Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.compactframework:52090
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

in my program I could edit picture and import them from a file.
we test recently from a 143Kb jpg and I have weird problem.

in the program it's stored as a byte[] data;
when the user want to see it I create the picture with

Bitmap b = new Bitmap(new MemoryStream(data));

what's really weird is if I look at the picture many times in a row
sometimes the bitmap creation failed.

any ideas ? tips ? experiences ?
 
Nice, just like Smeagol:
Graphicses
Good stuff Alex, good stuff!

Alex Feinman said:
Consider this:
instead
pictureBox1.Image = new Bitmap(...)
use
try
{
pictureBox1.Image.Dispose()
}
catch( ObjectDisposedException)
{
}
pictureBox1.Image = new Bitmap(...)


And yes - GC will eventually take care of bimtaps but each bitmap eats a lot
of GDI memory - much more than it does managed memory, so not calling
Dispose causes GDI memory to be exhausted long before there is any need for
GC to kick in. Thiis applies to all objects that have unmanaged data
attached - Events, Files, Brushes, Grapics (Graphicses?) etc


--
Alex Feinman
---
Visit http://www.opennetcf.org
Lloyd Dupont said:
mmhh....
well I might...
but I was told to trust the garbage collector !

anyway that's a good remark I will try to see if there is a possibility to
put some Dispose() somewhere .. (I mean the application was not thought this
way..)

just a question (which would ease my pain) could reuse a bitmap once it has
been disposed (explicitly by a call to Dispose()) ? or no ?

--
ihookdb
Get your data mobile
http://www.ihookdb.com


"Ilya Tumanov [MS]" said:
Lloyd,

Are you forgetting to dispose of bitmaps you no longer need?

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
From: "Lloyd Dupont" <net.galador@ld>
Subject: Bitmap ?!
Date: Fri, 30 Apr 2004 09:40:58 +1000
Lines: 20
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: adsl-11-233.swiftdsl.com.au 218.214.11.233
Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10
phx.gbl
Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.compactframework:52090
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

in my program I could edit picture and import them from a file.
we test recently from a 143Kb jpg and I have weird problem.

in the program it's stored as a byte[] data;
when the user want to see it I create the picture with

Bitmap b = new Bitmap(new MemoryStream(data));

what's really weird is if I look at the picture many times in a row
sometimes the bitmap creation failed.

any ideas ? tips ? experiences ?
 
True, I just love how he says "Nice Hobbitses" - could not resist <g>

--
Alex Feinman
---
Visit http://www.opennetcf.org
Chris Theorin said:
Nice, just like Smeagol:
Graphicses
Good stuff Alex, good stuff!

Alex Feinman said:
Consider this:
instead
pictureBox1.Image = new Bitmap(...)
use
try
{
pictureBox1.Image.Dispose()
}
catch( ObjectDisposedException)
{
}
pictureBox1.Image = new Bitmap(...)


And yes - GC will eventually take care of bimtaps but each bitmap eats a lot
of GDI memory - much more than it does managed memory, so not calling
Dispose causes GDI memory to be exhausted long before there is any need for
GC to kick in. Thiis applies to all objects that have unmanaged data
attached - Events, Files, Brushes, Grapics (Graphicses?) etc
possibility
to thought
this it
has
cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10
phx.gbl
Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.compactframework:52090
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

in my program I could edit picture and import them from a file.
we test recently from a 143Kb jpg and I have weird problem.

in the program it's stored as a byte[] data;
when the user want to see it I create the picture with

Bitmap b = new Bitmap(new MemoryStream(data));

what's really weird is if I look at the picture many times in a row
sometimes the bitmap creation failed.

any ideas ? tips ? experiences ?
 
Back
Top