C# New bitmap() - Out of memory -


i'm newbie @ dotnet programming. got serious problem me don't know why. used dispose() method "out of memory" problem still occurs. @ first 30 times, works perfectly. then, out of memory happens. furthermore, images 13-16mb. code:

private void advanbtn_click(object sender, eventargs e) {     invertfunction(); }  private void inverfunction() {     bitmap bm = new bitmap(imgbox.image); // out of memory     image<gray, byte> emguimage = new image<gray, byte>(bm);     emguimage = emguimage.not();     imgbox.image.dispose();     imgbox.image = emguimage.bitmap;     bm.dispose();     emguimage.dispose(); } 

try suggestion in documentation.

the time of when garbage collector decides dispose image not guaranteed. when working large image, recommend call dispose() method explicitly release object. alternatively, use using keyword in c# limit scope of image

    using (bitmap bm = new bitmap(imgbox.image))     {         using (image<gray, single> image = new image<gray, single>(bm))         {             emguimage = emguimage.not();             imgbox.image.dispose();             imgbox.image = emguimage.bitmap;         }     } 

as last resort can try forcing garbage collection. not recomended , should used if have no other way.

  gc.collect(); 

i suggest read before using here.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -