0

Am I coding something that is causing some type of memory issue

Metafile metFil = null;

Bitmap bmp = new Bitmap(x, y);

g = Graphics.FromImage(bmp);
  • As an aside, you're not calling `Dispose()` on your `Graphics` objects. `using (var g = Graphics.FromImage(...)) {}` – Ed S. Feb 14 '14 at 20:32
  • @EdS. or on the BitMap and it's likely the MetaFile isn't either. So lot's of unmanaged resources + no cleanup isn't great. Plus [there's this](http://stackoverflow.com/q/6333681/119477) – Conrad Frix Feb 14 '14 at 20:35
  • @ConradFrix: Yep, we just don't know what the calling code looks like. A safe bet considering the "leaked" `Graphics` objects. – Ed S. Feb 14 '14 at 20:41
  • Ed, what would be the correct way to code it with using/dispose? Thanks. – user3297350 Feb 14 '14 at 20:52
  • You will see this error when instantiating a new Bitmap when height and width parameters aren't realistic. Run through your debugger and check these values. Also, after you've used the graphics object, you'll need to call its Dispose method. It could be that your app is running out of resources after multiple calls. – u84six Feb 14 '14 at 21:19
  • In the calling function, there is a using: using (Graphics gt = Graphics.FromImage(bm))... Shouldn't that dispose it? – user3297350 Feb 14 '14 at 21:33
  • Make sure x and y are superior to zero. – Crono Feb 18 '14 at 13:29
  • Why did you remove such a massive ammount of your post, now your question is kind of pointless, the only answer we can give you now with the current edit is "you need to dispose `bmp` and `g`". – Scott Chamberlain Feb 18 '14 at 13:51
  • what are the value of `x` and `y` that are failing – Conrad Frix Feb 20 '14 at 15:16

0 Answers0