OutOfMemoryException on large file while burningannotation

Questions, comments and suggestions concerning VintaSoft Annotation .NET Plug-in.

Moderator: Alex

Post Reply
dada123
Posts: 4
Joined: Thu Feb 02, 2017 8:41 pm

OutOfMemoryException on large file while burningannotation

Post by dada123 » Thu Feb 02, 2017 8:45 pm

Hi, I have a 160 page TIFF with annotation on 70 pages. When I burn the annotations on all pages, I get the outofmemoryexception.

Any work around?

Alex
Site Admin
Posts: 1474
Joined: Thu Jul 10, 2008 2:21 pm

Re: OutOfMemoryException on large file while burningannotation

Post by Alex » Fri Feb 03, 2017 9:25 am

Hi,

Page is loaded in the memory when you burn the annotations on image. 70 pages are loaded in the memory when you burn the annotations on 70 images. I think your computer does not have enough memory for storing your images in memory. Please monitor the memory usage and save the burned images to the file for freeing the memory.

Best regards, Alexander

dada123
Posts: 4
Joined: Thu Feb 02, 2017 8:41 pm

Re: OutOfMemoryException on large file while burningannotation

Post by dada123 » Fri Feb 03, 2017 10:04 am

Hi Alex,

I revised the code like this:

Code: Select all

// Part of a method
imageViewer.Images.SaveAsync(saveDialog.FileName, encoder);
imageViewer.Images.ImageSaving += Images_ImageSaving;


// images_ImageSaving callback

private void Images_ImageSaving(object sender, ImageSavingEventArgs e)
{
    if (_burnImage)
    {
	Dispatcher.Invoke(new Action(() =>
	{
	    imageViewer.AnnotationViewController.BurnAnnotationCollectionOnImage(e.Image);
	}));
    }
}

Should I do it asynchronously or is there something that I can do to release the resources after burn and save?

Alex
Site Admin
Posts: 1474
Joined: Thu Jul 10, 2008 2:21 pm

Re: OutOfMemoryException on large file while burningannotation

Post by Alex » Fri Feb 03, 2017 12:05 pm

Hi,

Thank you for information. Could you send us a working project (with data), which allows to reproduce your problem? If yes, please send your project to support@vintasoft.com. If no, please check the memory usage, here is code snippet:

Code: Select all

// subscribe to the events of image collection
imageViewer.Images.ImageSaving += Images_ImageSaving;
imageViewer.Images.ImageCollectionSavingFinished += Images_ImageCollectionSavingFinished;

Console.WriteLine(string.Format("Mem usage before save: {0}", Environment.WorkingSet));
// save image collection asynchronously
imageViewer.Images.SaveAsync(saveDialog.FileName, encoder);


private void Images_ImageSaving(object sender, ImageSavingEventArgs e)
{
    if (_burnImage)
    {
        Dispatcher.Invoke(new Action(() =>
        {
            Console.WriteLine(string.Format("Mem usage before burn: {0}", Environment.WorkingSet));
            imageViewer.AnnotationViewController.BurnAnnotationCollectionOnImage(e.Image);
            Console.WriteLine(string.Format("Mem usage after burn: {0}", Environment.WorkingSet));
        }));
    }
}

private void Images_ImageCollectionSavingFinished(object sender, EventArgs e)
{
    Console.WriteLine(string.Format("Mem usage after save: {0}", Environment.WorkingSet));
}
Best regards, Alexander

dada123
Posts: 4
Joined: Thu Feb 02, 2017 8:41 pm

Re: OutOfMemoryException on large file while burningannotation

Post by dada123 » Fri Feb 03, 2017 1:13 pm

Hi, here's the memory usage. The TIF file is classified so I can't give it to you. This is a 160 page high res TIF file with annotation on at least 20 pages. This one did not crash. I forgot to mention that the application is 32-bit. 64-bit is not an option because we are still supporting XP in the workplace.

Thanks for your time.

Code: Select all

Mem usage before save: 262926336
Mem usage before burn: 264941568
Mem usage after burn: 306966528
Mem usage before burn: 307740672
Mem usage after burn: 304508928
Mem usage before burn: 284295168
Mem usage after burn: 318599168
Mem usage before burn: 298295296
Mem usage after burn: 298295296
Mem usage before burn: 289853440
Mem usage after burn: 289853440
Mem usage before burn: 289857536
Mem usage after burn: 289857536
Mem usage before burn: 292573184
Mem usage after burn: 292573184
Mem usage before burn: 292573184
Mem usage after burn: 292573184
Mem usage before burn: 295231488
Mem usage after burn: 295235584
Mem usage before burn: 295243776
Mem usage after burn: 295243776
Mem usage before burn: 297472000
Mem usage after burn: 297533440
Mem usage before burn: 297594880
Mem usage after burn: 297594880
Mem usage before burn: 297930752
Mem usage after burn: 297930752
Mem usage before burn: 297934848
Mem usage after burn: 297934848
Mem usage before burn: 296439808
Mem usage after burn: 296439808
Mem usage before burn: 296603648
Mem usage after burn: 296607744
Mem usage before burn: 298831872
Mem usage after burn: 298868736
Mem usage before burn: 298999808
Mem usage after burn: 298999808
Mem usage before burn: 289873920
Mem usage after burn: 289873920
Mem usage before burn: 289873920
Mem usage after burn: 289873920
Mem usage before burn: 293695488
Mem usage after burn: 293715968
Mem usage before burn: 293756928
Mem usage after burn: 293765120
Mem usage before burn: 294195200
Mem usage after burn: 294232064
Mem usage before burn: 294305792
Mem usage after burn: 294305792
Mem usage before burn: 294051840
Mem usage after burn: 294051840
Mem usage before burn: 294051840
Mem usage after burn: 294051840
Mem usage before burn: 296853504
Mem usage after burn: 296894464
Mem usage before burn: 296992768
Mem usage after burn: 297005056
Mem usage before burn: 295981056
Mem usage after burn: 295813120
Mem usage before burn: 295981056
Mem usage after burn: 295981056
Mem usage before burn: 296747008
Mem usage after burn: 296747008
Mem usage before burn: 296628224
Mem usage after burn: 296628224
Mem usage before burn: 297963520
Mem usage after burn: 297984000
Mem usage before burn: 298160128
Mem usage after burn: 298803200
Mem usage before burn: 299651072
Mem usage after burn: 299651072
Mem usage before burn: 299819008
Mem usage after burn: 299819008
Mem usage before burn: 300924928
Mem usage after burn: 300924928
Mem usage before burn: 300924928
Mem usage after burn: 300924928
Mem usage before burn: 300597248
Mem usage after burn: 300597248
Mem usage before burn: 300597248
Mem usage after burn: 300597248
Mem usage before burn: 300552192
Mem usage after burn: 300552192
Mem usage before burn: 300552192
Mem usage after burn: 300552192
Mem usage before burn: 300625920
Mem usage after burn: 300625920
Mem usage before burn: 300625920
Mem usage after burn: 300625920
Mem usage before burn: 300552192
Mem usage after burn: 300552192
Mem usage before burn: 300552192
Mem usage after burn: 300552192
Mem usage before burn: 300527616
Mem usage after burn: 300527616
Mem usage before burn: 300527616
Mem usage after burn: 300527616
Mem usage before burn: 300564480
Mem usage after burn: 300564480
Mem usage before burn: 300564480
Mem usage after burn: 300564480
Mem usage before burn: 300601344
Mem usage after burn: 300601344
Mem usage before burn: 300601344
Mem usage after burn: 300601344
Mem usage before burn: 300548096
Mem usage after burn: 300548096
Mem usage before burn: 300548096
Mem usage after burn: 300548096
Mem usage before burn: 300576768
Mem usage after burn: 300576768
Mem usage before burn: 300576768
Mem usage after burn: 300576768
Mem usage before burn: 300826624
Mem usage after burn: 300826624
Mem usage before burn: 300826624
Mem usage after burn: 300826624
Mem usage before burn: 300670976
Mem usage after burn: 300670976
Mem usage before burn: 300670976
Mem usage after burn: 300670976
Mem usage before burn: 300670976
Mem usage after burn: 300670976
Mem usage before burn: 300670976
Mem usage after burn: 300670976
Mem usage before burn: 300675072
Mem usage after burn: 300675072
Mem usage before burn: 300675072
Mem usage after burn: 300675072
Mem usage before burn: 300675072
Mem usage after burn: 300675072
Mem usage before burn: 300675072
Mem usage after burn: 300675072
Mem usage before burn: 300675072
Mem usage after burn: 300675072
Mem usage before burn: 300675072
Mem usage after burn: 300675072
Mem usage before burn: 300675072
Mem usage after burn: 300675072
Mem usage before burn: 300675072
Mem usage after burn: 300675072
Mem usage before burn: 300552192
Mem usage after burn: 300552192
Mem usage before burn: 300552192
Mem usage after burn: 300552192
Mem usage before burn: 300552192
Mem usage after burn: 300552192
Mem usage before burn: 300552192
Mem usage after burn: 300552192
Mem usage before burn: 300552192
Mem usage after burn: 300552192
Mem usage before burn: 300552192
Mem usage after burn: 300552192
Mem usage before burn: 300552192
Mem usage after burn: 300552192
Mem usage before burn: 300552192
Mem usage after burn: 300552192
Mem usage before burn: 300552192
Mem usage after burn: 300552192
Mem usage before burn: 300552192
Mem usage after burn: 300552192
Mem usage before burn: 300515328
Mem usage after burn: 300515328
Mem usage before burn: 300515328
Mem usage after burn: 300515328
Mem usage before burn: 300515328
Mem usage after burn: 300515328
Mem usage before burn: 300515328
Mem usage after burn: 300515328
Mem usage before burn: 300515328
Mem usage after burn: 300515328
Mem usage before burn: 300515328
Mem usage after burn: 300515328
Mem usage before burn: 300515328
Mem usage after burn: 300515328
Mem usage before burn: 300515328
Mem usage after burn: 300515328
Mem usage before burn: 300642304
Mem usage after burn: 300642304
Mem usage before burn: 300642304
Mem usage after burn: 300642304
Mem usage before burn: 300646400
Mem usage after burn: 300646400
Mem usage before burn: 300646400
Mem usage after burn: 300646400
Mem usage before burn: 300646400
Mem usage after burn: 300646400
Mem usage before burn: 300646400
Mem usage after burn: 300646400
Mem usage before burn: 300646400
Mem usage after burn: 300646400
Mem usage before burn: 300646400
Mem usage after burn: 300646400
Mem usage before burn: 300646400
Mem usage after burn: 300646400
Mem usage before burn: 300646400
Mem usage after burn: 300646400
Mem usage before burn: 300646400
Mem usage after burn: 300646400
Mem usage before burn: 300646400
Mem usage after burn: 300646400
Mem usage before burn: 300646400
Mem usage after burn: 300646400
Mem usage before burn: 300646400
Mem usage after burn: 300646400
Mem usage before burn: 301064192
Mem usage after burn: 301064192
Mem usage before burn: 301064192
Mem usage after burn: 301064192
Mem usage before burn: 300445696
Mem usage after burn: 300445696
Mem usage before burn: 300445696
Mem usage after burn: 300445696
Mem usage before burn: 300449792
Mem usage after burn: 300449792
Mem usage before burn: 300449792
Mem usage after burn: 300449792
Mem usage before burn: 300449792
Mem usage after burn: 300449792
Mem usage before burn: 300449792
Mem usage after burn: 300449792
Mem usage before burn: 300449792
Mem usage after burn: 300449792
Mem usage before burn: 300449792
Mem usage after burn: 300449792
Mem usage before burn: 300449792
Mem usage after burn: 300449792
Mem usage before burn: 300449792
Mem usage after burn: 300449792
Mem usage before burn: 300449792
Mem usage after burn: 300449792
Mem usage before burn: 300449792
Mem usage after burn: 300449792
Mem usage before burn: 300449792
Mem usage after burn: 300449792
Mem usage before burn: 300449792
Mem usage after burn: 300449792
Mem usage before burn: 300453888
Mem usage after burn: 300453888
Mem usage before burn: 300453888
Mem usage after burn: 300453888
Mem usage before burn: 300453888
Mem usage after burn: 300453888
Mem usage before burn: 300453888
Mem usage after burn: 300453888
Mem usage before burn: 300453888
Mem usage after burn: 300453888
Mem usage before burn: 300453888
Mem usage after burn: 300453888
Mem usage before burn: 300453888
Mem usage after burn: 300453888
Mem usage before burn: 300453888
Mem usage after burn: 300453888
Mem usage before burn: 300453888
Mem usage after burn: 300453888
Mem usage before burn: 300453888
Mem usage after burn: 300453888
Mem usage before burn: 300453888
Mem usage after burn: 300453888
Mem usage before burn: 300453888
Mem usage after burn: 300453888
Mem usage before burn: 300433408
Mem usage after burn: 300433408
Mem usage before burn: 300433408
Mem usage after burn: 300433408
Mem usage before burn: 300433408
Mem usage after burn: 300433408
Mem usage before burn: 300433408
Mem usage after burn: 300433408
Mem usage before burn: 300433408
Mem usage after burn: 300433408
Mem usage before burn: 300433408
Mem usage after burn: 300433408
Mem usage before burn: 300433408
Mem usage after burn: 300433408
Mem usage before burn: 300433408
Mem usage after burn: 300433408
Mem usage before burn: 300433408
Mem usage after burn: 300433408
Mem usage before burn: 300433408
Mem usage after burn: 300433408
Mem usage before burn: 300433408
Mem usage after burn: 300433408
Mem usage before burn: 300433408
Mem usage after burn: 300433408
Mem usage before burn: 300953600
Mem usage after burn: 300953600
Mem usage before burn: 300953600
Mem usage after burn: 300953600
Mem usage before burn: 300408832
Mem usage after burn: 300408832
Mem usage before burn: 300408832
Mem usage after burn: 300408832
Mem usage before burn: 300408832
Mem usage after burn: 300408832
Mem usage before burn: 300408832
Mem usage after burn: 300408832
Mem usage before burn: 300408832
Mem usage after burn: 300408832
Mem usage before burn: 300408832
Mem usage after burn: 300408832
Mem usage before burn: 300408832
Mem usage after burn: 300408832
Mem usage before burn: 300408832
Mem usage after burn: 300408832
Mem usage before burn: 300408832
Mem usage after burn: 300408832
Mem usage before burn: 300408832
Mem usage after burn: 300408832
Mem usage before burn: 300408832
Mem usage after burn: 300408832
Mem usage before burn: 300408832
Mem usage after burn: 300408832
Mem usage before burn: 300408832
Mem usage after burn: 300408832
Mem usage before burn: 300408832
Mem usage after burn: 300408832
Mem usage before burn: 300408832
Mem usage after burn: 300408832
Mem usage before burn: 300408832
Mem usage after burn: 300408832
Mem usage before burn: 300408832
Mem usage after burn: 300408832
Mem usage before burn: 300408832
Mem usage after burn: 300408832
Mem usage before burn: 300408832
Mem usage after burn: 300408832
Mem usage before burn: 300408832
Mem usage after burn: 300408832
Mem usage before burn: 300408832
Mem usage after burn: 376369152
Mem usage before burn: 376582144
Mem usage after burn: 376614912
Mem usage before burn: 332673024
Mem usage after burn: 408543232
Mem usage before burn: 408739840
Mem usage after burn: 408801280
Mem usage before burn: 364707840
Mem usage after burn: 440598528
Mem usage before burn: 441827328
Mem usage after burn: 441884672
Mem usage before burn: 396877824
Mem usage after burn: 472780800
Mem usage before burn: 473231360
Mem usage after burn: 473296896
Mem usage before burn: 429031424
Mem usage after burn: 504803328
Mem usage before burn: 505184256
Mem usage after burn: 505245696
Mem usage before burn: 461189120
Mem usage after burn: 536891392
Mem usage before burn: 537354240
Mem usage after burn: 537403392
Mem usage before burn: 493375488
Mem usage after burn: 569098240
Mem usage before burn: 569487360
Mem usage after burn: 569565184
Mem usage before burn: 525537280
Mem usage after burn: 525537280
Mem usage before burn: 525537280
Mem usage after burn: 525537280
Mem usage before burn: 525565952
Mem usage after burn: 525565952
Mem usage before burn: 525565952
Mem usage after burn: 525565952
Mem usage before burn: 525565952
Mem usage after burn: 525565952
Mem usage before burn: 525565952
Mem usage after burn: 525565952
Mem usage before burn: 525565952
Mem usage after burn: 525565952
Mem usage before burn: 525565952
Mem usage after burn: 525565952
Mem usage before burn: 525869056
Mem usage after burn: 525869056
Mem usage before burn: 525869056
Mem usage after burn: 525869056
Mem usage before burn: 526966784
Mem usage after burn: 526966784
Mem usage before burn: 526966784
Mem usage after burn: 526966784
Mem usage before burn: 526966784
Mem usage after burn: 526966784
Mem usage before burn: 526966784
Mem usage after burn: 526966784
Mem usage before burn: 525635584
Mem usage after burn: 525635584
Mem usage before burn: 525635584
Mem usage after burn: 525635584
Mem usage before burn: 525635584
Mem usage after burn: 525635584
Mem usage before burn: 525635584
Mem usage after burn: 525635584
Mem usage before burn: 525635584
Mem usage after burn: 525635584
Mem usage before burn: 525635584
Mem usage after burn: 525635584
Mem usage before burn: 525635584
Mem usage after burn: 525635584
Mem usage before burn: 525635584
Mem usage after burn: 525635584
Mem usage before burn: 525635584
Mem usage after burn: 525635584
Mem usage before burn: 525635584
Mem usage after burn: 525635584
Mem usage before burn: 525635584
Mem usage after burn: 525635584
Mem usage before burn: 525635584
Mem usage after burn: 525635584
Mem usage before burn: 525635584
Mem usage after burn: 525635584
Mem usage before burn: 525635584
Mem usage after burn: 525635584
Mem usage before burn: 525807616
Mem usage after burn: 525807616
Mem usage before burn: 525807616
Mem usage after burn: 525807616
Mem usage before burn: 525807616
Mem usage after burn: 525807616
Mem usage before burn: 525807616
Mem usage after burn: 525807616
Mem usage before burn: 525807616
Mem usage after burn: 525807616
Mem usage before burn: 525807616
Mem usage after burn: 525807616
Mem usage before burn: 525807616
Mem usage after burn: 525807616
Mem usage before burn: 525807616
Mem usage after burn: 525807616
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 525516800
Mem usage before burn: 525516800
Mem usage after burn: 601739264
Mem usage before burn: 602042368
Mem usage after burn: 602116096
Mem usage before burn: 557674496
Mem usage after burn: 633221120
Mem usage before burn: 633790464
Mem usage after burn: 633835520
Mem usage before burn: 589742080
Mem usage after burn: 665513984
Mem usage before burn: 665710592
Mem usage after burn: 665755648
Mem usage before burn: 621846528
Mem usage after burn: 697683968
Mem usage before burn: 698081280
Mem usage after burn: 698134528
Mem usage before burn: 654389248
Mem usage after burn: 730009600
Mem usage before burn: 731484160
Mem usage after burn: 731566080
Mem usage before burn: 686133248
Mem usage after burn: 761778176
Mem usage before burn: 762269696
Mem usage after burn: 762318848
Mem usage before burn: 718274560
Mem usage after burn: 793985024
Mem usage before burn: 794591232
Mem usage after burn: 794660864
Mem usage before burn: 750428160
Mem usage after burn: 750428160
Mem usage before burn: 750428160
Mem usage after burn: 750428160
Mem usage before burn: 750456832
Mem usage after burn: 826298368
Mem usage before burn: 826736640
Mem usage after burn: 826806272
Mem usage before burn: 782569472
Mem usage after burn: 858316800
Mem usage before burn: 860188672
Mem usage after burn: 860258304
Mem usage before burn: 814731264
Mem usage after burn: 890621952
Mem usage before burn: 890945536
Mem usage after burn: 891002880
Mem usage before burn: 846893056
Mem usage after burn: 922783744
Mem usage before burn: 923021312
Mem usage after burn: 923070464
Mem usage before burn: 879034368
Mem usage after burn: 954839040
Mem usage before burn: 955711488
Mem usage after burn: 955777024
Mem usage before burn: 911224832
Mem usage after burn: 986243072
Mem usage before burn: 987533312
Mem usage after burn: 987615232
Mem usage before burn: 943370240
Mem usage after burn: 1018384384
Mem usage before burn: 1023799296
Mem usage after burn: 1023893504
Mem usage before burn: 975527936
Mem usage after burn: 975527936
Mem usage before burn: 975527936
Mem usage after burn: 975527936
Mem usage before burn: 975560704
Mem usage after burn: 975560704
Mem usage before burn: 975560704
Mem usage after burn: 975560704
Mem usage before burn: 975560704
Mem usage after burn: 975560704
Mem usage before burn: 975560704
Mem usage after burn: 975560704
Mem usage before burn: 975560704
Mem usage after burn: 975560704
Mem usage before burn: 975560704
Mem usage after burn: 975560704
Mem usage before burn: 975560704
Mem usage after burn: 975560704
Mem usage before burn: 975560704
Mem usage after burn: 975560704
Mem usage before burn: 975560704
Mem usage after burn: 975560704
Mem usage before burn: 975560704
Mem usage after burn: 975560704
Mem usage before burn: 976199680
Mem usage after burn: 976199680
Mem usage before burn: 976199680
Mem usage after burn: 976199680
Mem usage before burn: 976199680
Mem usage after burn: 976199680
Mem usage before burn: 976199680
Mem usage after burn: 976199680
Mem usage before burn: 976199680
Mem usage after burn: 976199680
Mem usage before burn: 976199680
Mem usage after burn: 976199680
Mem usage before burn: 976199680
Mem usage after burn: 976199680
Mem usage before burn: 976199680
Mem usage after burn: 976199680
Mem usage before burn: 976199680
Mem usage after burn: 976199680
Mem usage before burn: 976199680
Mem usage after burn: 976199680
Mem usage before burn: 976199680
Mem usage after burn: 976199680
Mem usage before burn: 976199680
Mem usage after burn: 976199680
Mem usage before burn: 976199680
Mem usage after burn: 976199680
Mem usage before burn: 976199680
Mem usage after burn: 976199680
Mem usage before burn: 976519168
Mem usage after burn: 976519168
Mem usage before burn: 976519168
Mem usage after burn: 976519168
Mem usage before burn: 975761408
Mem usage after burn: 975761408
Mem usage before burn: 975761408
Mem usage after burn: 975761408
Mem usage before burn: 975761408
Mem usage after burn: 975761408
Mem usage before burn: 975761408
Mem usage after burn: 975761408
Mem usage before burn: 975761408
Mem usage after burn: 975761408
Mem usage before burn: 975761408
Mem usage after burn: 975761408
Mem usage before burn: 975761408
Mem usage after burn: 975761408
Mem usage before burn: 975761408
Mem usage after burn: 975761408
Mem usage before burn: 975761408
Mem usage after burn: 975761408
Mem usage before burn: 975761408
Mem usage after burn: 975761408
Mem usage before burn: 975761408
Mem usage after burn: 975761408
Mem usage before burn: 975761408
Mem usage after burn: 975761408
Mem usage before burn: 975740928
Mem usage after burn: 975740928
Mem usage before burn: 975740928
Mem usage after burn: 975740928
Mem usage before burn: 975740928
Mem usage after burn: 975740928
Mem usage before burn: 975740928
Mem usage after burn: 975740928
Mem usage after save: 975740928

Alex
Site Admin
Posts: 1474
Joined: Thu Jul 10, 2008 2:21 pm

Re: OutOfMemoryException on large file while burningannotation

Post by Alex » Mon Feb 06, 2017 11:41 am

Hello,

The AnnotationViewController.BurnAnnotationCollectionOnImage method burns annotations on image, for doing this method loads image into the memory. In your code you are burning annotations on each saving image, i.e. you are loading all images with annotations into memory and as a result you can have the OutOfMemoryException when all available memory will be used.

For solving the problem you need burn annotations on image and dispose image when image is not necessary any more.

Here is code that allows to burn annotations on images, save images to a TIFF file and prevent the OutOfMemoryException:

Code: Select all

private void SaveImagesWithAnnotations(WpfAnnotationViewer viewer, string filePath)
{
    ImageCollection collection = viewer.Images;
    WpfAnnotationViewController controller = viewer.AnnotationViewController;

    using (TiffEncoder encoder = new TiffEncoder())
    {
        encoder.CreateNewFile = true;
        using (Stream stream = File.Create(filePath))
        {
            for (int i = 0; i < collection.Count; i++)
            {
                if (controller.GetAnnotationsView(i).Count > 0)
                {
                    using (VintasoftImage image = controller.GetImageWithAnnotations(i))
                    {
                        encoder.SaveImage(image, stream);
                    }
                }
                else
                {
                    encoder.SaveImage(collection[i], stream);
                }

                encoder.CreateNewFile = false;
            }
        }
    }
}
Best regards, Alexander

dada123
Posts: 4
Joined: Thu Feb 02, 2017 8:41 pm

Re: OutOfMemoryException on large file while burningannotation

Post by dada123 » Mon Feb 06, 2017 12:32 pm

Thanks Alex, problem solved :)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest