Northern
Northern

Reputation: 189

How many Bitmaps can I create in .NET?

.NET Bitmap class uses GDI+

I want to know how many Bitmaps I can create.

Will memory leak when create too many Bitmaps?

Upvotes: 0

Views: 522

Answers (6)

x77
x77

Reputation: 737

Windows XP and Vista - default limit

The default limit in Windows XP and Vista is 10,000. You can monitor the number of GDI objects an application has from the "task manager"

http://msdn.microsoft.com/en-us/library/ms724291(VS.85).aspx

Note: I tested a PrintPreview with HashMorePages = True until It Throw Exception (about 4800 pages), Each Page needs 2 Gdi+ objects.

Upvotes: 0

Michał Piaskowski
Michał Piaskowski

Reputation: 3850

MSDN says

There is a theoretical limit of 65,536 GDI handles per session. However, the maximum number of GDI handles that can be opened per session is usually lower, since it is affected by available memory.

Source: http://msdn.microsoft.com/en-us/library/ms724291%28VS.85%29.aspx

Upvotes: 2

Daniel Rose
Daniel Rose

Reputation: 17648

The limit of GDI handles is 65536 per session. See http://msdn.microsoft.com/en-us/library/ms724291(VS.85).aspx

Upvotes: 2

Arseny
Arseny

Reputation: 7361

Bitmap is a GDI+ object and you get limited number of those object in your system. Of course you may adjust the system. I don't think you will get memory leak but a system exception in case you exceed that limit.

Upvotes: 0

Rupeshit
Rupeshit

Reputation: 1466

You will might be face memory leak problem but you can fix it by writing simple code

      using (frame) {
          frame.Save(outStream, jpegCodec, parameters);
      }

Upvotes: 0

cHao
cHao

Reputation: 86555

Memory won't leak as long as you use the framework to make them. The Bitmap class is made in such a way that instances dispose themselves when finalized, as any self-respecting IDisposable does, so even forgetting to Dispose it won't cause issues.

As for how many you can make, that depends on how much memory you have to work with.

Upvotes: 2

Related Questions