cameron314 / PNGEncoder2

A better PNG encoder for Flash
97 stars 10 forks source link

Error #1000: The system is out of memory #5

Closed damoebius closed 9 years ago

damoebius commented 11 years ago

Hi, I've got an Exception while encoding a huge picture, 6201x6201px in a Air 3.4 application.

at flash.utils::ByteArray/set length() at _PNGEncoder2::PNGEncoder2Impl$/writeIDATChunk() at PNGEncoder2$/encode() Before encoding call, Scout tell me that i used only 200MB of memory and After exception, system memory manager tell me that adl.exe used 1.5GB.

Is there a way to optimize memory usage of your encoder ? Is it possible to encode partial part of the picture but save a full PNG with FileStream for exemple ?

cameron314 commented 11 years ago

Hi :-)

Use the asynchronous mode -- it encodes only one chunk of the image at once (repeatedly), which should reduce memory usage to something very reasonable.

If after that you're finding the actual generated PNG file too large, you can try the GOOD setting for better compression.

Since you want to write the result to a file in the end anyway, I suggest you use the gh-IDataOutput branch (I've kept it in sync with the master branch -- the only difference is it takes an IDataOutput object, such as a FileStream, directly instead of producing a ByteArray). That should limit the memory overhead to a constant amount.

damoebius commented 11 years ago

You are right. Using asynchronous mode reduce memory usage enough. I'll have a look on your IDataOutput because using a FileStream is realy an amazing feature.

2013/10/3 Cameron notifications@github.com

Hi :-)

Use the asynchronous mode -- it encodes only one chunk of the image at once (repeatedly), which should reduce memory usage to something very reasonable.

If after that you're finding the actual generated PNG file too large, you can try the GOOD setting for better compression.

Since you want to write the result to a file in the end anyway, I suggest you use the gh-IDataOutput branch (I've kept it in sync with the master branch -- the only difference is it takes an IDataOutput object, such as a FileStream, directly instead of producing a ByteArray).

— Reply to this email directly or view it on GitHubhttps://github.com/cameron314/PNGEncoder2/issues/5#issuecomment-25633384 .

cameron314 commented 9 years ago

For anybody else looking at this issue, there's also the new freeCachedMemory method which you can call after an image has finished being encoded. It will release all temporary memory that was used during the encoding process.