You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Ankit Agarwal <an...@gmail.com> on 2016/06/24 07:55:53 UTC

PDFRendering

Hi,
When i try to covert pdf to image then for some pdfs i get a "out of
memory" error. So i increased heap size and then i again got the error for
some different pdf file.
for the time being assume I have no memory leak from other objects. So what
would be the reason for this memory out of error?
Would it be just that the image is so large(which is not the case i think)
that it consumes heap, or maybe pdfbox stores buffered image of each pages
in its memory and this contributes to the growing heap size?
Any insight would be wonderful.

Re: PDFRendering

Posted by Ankit Agarwal <an...@gmail.com>.
I have checked my code again and again and there is no leak due to
uncleared reference to objects.

I ran some more pdf files and it seems that I get a memory error only for
some specific pdf files.

My conclusion:- We are just using too much memory(as John Hewson said).

On Tue, Jun 28, 2016 at 3:16 AM, John Lussmyer <Co...@casadelgato.com>
wrote:

> On Mon Jun 27 14:34:03 PDT 2016 john@jahewson.com said:
> >Right, and if it was a leak then system.gc would not have fixed it.
>
> That is only SOMETIMES true.  I've run into "memory leaks" where the leak
> was uncleared references to objects.  So the old objects just hung around
> forever.
>
>
> --
>
> Bobcats and Cougars, oh my!  http://john.casadelgato.com/Pets
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>

Re: PDFRendering

Posted by John Lussmyer <Co...@CasaDelGato.com>.
On Mon Jun 27 14:34:03 PDT 2016 john@jahewson.com said:
>Right, and if it was a leak then system.gc would not have fixed it. 

That is only SOMETIMES true.  I've run into "memory leaks" where the leak was uncleared references to objects.  So the old objects just hung around forever.


--

Bobcats and Cougars, oh my!  http://john.casadelgato.com/Pets

Re: PDFRendering

Posted by John Hewson <jo...@jahewson.com>.
> On 27 Jun 2016, at 09:54, Ankit Agarwal <an...@gmail.com> wrote:
> 
> I was getting the error even when I was rendering just 3-4 pages. So i
> don't think it was due to any memory leak.

Right, and if it was a leak then system.gc would not have fixed it. So it looks like we're just using too much memory.

-- John

> On Mon, Jun 27, 2016 at 10:17 PM, Ankit Agarwal <an...@gmail.com>
> wrote:
> 
>> Hi, Thanks for the reply.
>> I am using  32 bit jvm and 1.5 gb of heap size.
>> Still I was getting out of memory error when i was rendering pdf with
>> multiple pages.
>> When i introduced system.gc call after each page (which is not ideal and
>> bad programming choice) , then the pages were being rendered without an
>> error.
>> So I think that the bufferedImage from previous page wasn't being cleared
>> and the next page was loaded( but in my code the image object is flushed
>> before another use so this shouldn't happen).Anyways system.gc() solved
>> this for now.
>> But as we know we cannot be sure that system.gc() will call the garbage
>> colelctor as the final decision lies with the jvm. So I guess, I'll just
>> have to try my luck here and continue with the code.
>> Thanks
>> 
>> On Mon, Jun 27, 2016 at 9:17 PM, Tilman Hausherr <TH...@t-online.de>
>> wrote:
>> 
>>>> Am 27.06.2016 um 15:39 schrieb John Hewson:
>>>> 
>>>>> On 24 Jun 2016, at 00:55, Ankit Agarwal <an...@gmail.com> wrote:
>>>>> 
>>>>> Hi,
>>>>> When i try to covert pdf to image then for some pdfs i get a "out of
>>>>> memory" error. So i increased heap size and then i again got the error
>>>>> for
>>>>> some different pdf file.
>>>>> for the time being assume I have no memory leak from other objects. So
>>>>> what
>>>>> would be the reason for this memory out of error?
>>>>> Would it be just that the image is so large(which is not the case i
>>>>> think)
>>>>> that it consumes heap, or maybe pdfbox stores buffered image of each
>>>>> pages
>>>>> in its memory and this contributes to the growing heap size?
>>>>> Any insight would be wonderful.
>>>> Usually it’s because the PDF contains a compressed image which is very
>>>> large
>>>> when decompressed. So the file isn’t big on disk, but it is in memory.
>>>> Try using
>>>> a 32-bit JVM as these use less memory. 1GB of heap is usually enough but
>>>> you
>>>> can go larger.
>>> 
>>> He does use 32bit JVM. I tried two of his files on a 64bit JVM and it has
>>> rendered for 24 hours with -Xmx400m.
>>> 
>>> 
>>> https://stackoverflow.com/questions/38008475/pdf-rendering-using-pdfbox/38010316#38010316
>>> 
>>> Tilman
>>> 
>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: PDFRendering

Posted by Ankit Agarwal <an...@gmail.com>.
I was getting the error even when I was rendering just 3-4 pages. So i
don't think it was due to any memory leak.

On Mon, Jun 27, 2016 at 10:17 PM, Ankit Agarwal <an...@gmail.com>
wrote:

> Hi, Thanks for the reply.
> I am using  32 bit jvm and 1.5 gb of heap size.
> Still I was getting out of memory error when i was rendering pdf with
> multiple pages.
> When i introduced system.gc call after each page (which is not ideal and
> bad programming choice) , then the pages were being rendered without an
> error.
> So I think that the bufferedImage from previous page wasn't being cleared
> and the next page was loaded( but in my code the image object is flushed
> before another use so this shouldn't happen).Anyways system.gc() solved
> this for now.
> But as we know we cannot be sure that system.gc() will call the garbage
> colelctor as the final decision lies with the jvm. So I guess, I'll just
> have to try my luck here and continue with the code.
> Thanks
>
> On Mon, Jun 27, 2016 at 9:17 PM, Tilman Hausherr <TH...@t-online.de>
> wrote:
>
>> Am 27.06.2016 um 15:39 schrieb John Hewson:
>>
>>> On 24 Jun 2016, at 00:55, Ankit Agarwal <an...@gmail.com> wrote:
>>>>
>>>> Hi,
>>>> When i try to covert pdf to image then for some pdfs i get a "out of
>>>> memory" error. So i increased heap size and then i again got the error
>>>> for
>>>> some different pdf file.
>>>> for the time being assume I have no memory leak from other objects. So
>>>> what
>>>> would be the reason for this memory out of error?
>>>> Would it be just that the image is so large(which is not the case i
>>>> think)
>>>> that it consumes heap, or maybe pdfbox stores buffered image of each
>>>> pages
>>>> in its memory and this contributes to the growing heap size?
>>>> Any insight would be wonderful.
>>>>
>>> Usually it’s because the PDF contains a compressed image which is very
>>> large
>>> when decompressed. So the file isn’t big on disk, but it is in memory.
>>> Try using
>>> a 32-bit JVM as these use less memory. 1GB of heap is usually enough but
>>> you
>>> can go larger.
>>>
>>
>> He does use 32bit JVM. I tried two of his files on a 64bit JVM and it has
>> rendered for 24 hours with -Xmx400m.
>>
>>
>> https://stackoverflow.com/questions/38008475/pdf-rendering-using-pdfbox/38010316#38010316
>>
>> Tilman
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>>
>

Re: PDFRendering

Posted by Ankit Agarwal <an...@gmail.com>.
Hi, Thanks for the reply.
I am using  32 bit jvm and 1.5 gb of heap size.
Still I was getting out of memory error when i was rendering pdf with
multiple pages.
When i introduced system.gc call after each page (which is not ideal and
bad programming choice) , then the pages were being rendered without an
error.
So I think that the bufferedImage from previous page wasn't being cleared
and the next page was loaded( but in my code the image object is flushed
before another use so this shouldn't happen).Anyways system.gc() solved
this for now.
But as we know we cannot be sure that system.gc() will call the garbage
colelctor as the final decision lies with the jvm. So I guess, I'll just
have to try my luck here and continue with the code.
Thanks

On Mon, Jun 27, 2016 at 9:17 PM, Tilman Hausherr <TH...@t-online.de>
wrote:

> Am 27.06.2016 um 15:39 schrieb John Hewson:
>
>> On 24 Jun 2016, at 00:55, Ankit Agarwal <an...@gmail.com> wrote:
>>>
>>> Hi,
>>> When i try to covert pdf to image then for some pdfs i get a "out of
>>> memory" error. So i increased heap size and then i again got the error
>>> for
>>> some different pdf file.
>>> for the time being assume I have no memory leak from other objects. So
>>> what
>>> would be the reason for this memory out of error?
>>> Would it be just that the image is so large(which is not the case i
>>> think)
>>> that it consumes heap, or maybe pdfbox stores buffered image of each
>>> pages
>>> in its memory and this contributes to the growing heap size?
>>> Any insight would be wonderful.
>>>
>> Usually it’s because the PDF contains a compressed image which is very
>> large
>> when decompressed. So the file isn’t big on disk, but it is in memory.
>> Try using
>> a 32-bit JVM as these use less memory. 1GB of heap is usually enough but
>> you
>> can go larger.
>>
>
> He does use 32bit JVM. I tried two of his files on a 64bit JVM and it has
> rendered for 24 hours with -Xmx400m.
>
>
> https://stackoverflow.com/questions/38008475/pdf-rendering-using-pdfbox/38010316#38010316
>
> Tilman
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>

Re: PDFRendering

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 27.06.2016 um 15:39 schrieb John Hewson:
>> On 24 Jun 2016, at 00:55, Ankit Agarwal <an...@gmail.com> wrote:
>>
>> Hi,
>> When i try to covert pdf to image then for some pdfs i get a "out of
>> memory" error. So i increased heap size and then i again got the error for
>> some different pdf file.
>> for the time being assume I have no memory leak from other objects. So what
>> would be the reason for this memory out of error?
>> Would it be just that the image is so large(which is not the case i think)
>> that it consumes heap, or maybe pdfbox stores buffered image of each pages
>> in its memory and this contributes to the growing heap size?
>> Any insight would be wonderful.
> Usually it\u2019s because the PDF contains a compressed image which is very large
> when decompressed. So the file isn\u2019t big on disk, but it is in memory. Try using
> a 32-bit JVM as these use less memory. 1GB of heap is usually enough but you
> can go larger.

He does use 32bit JVM. I tried two of his files on a 64bit JVM and it 
has rendered for 24 hours with -Xmx400m.

https://stackoverflow.com/questions/38008475/pdf-rendering-using-pdfbox/38010316#38010316

Tilman



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: PDFRendering

Posted by John Hewson <jo...@jahewson.com>.
> On 24 Jun 2016, at 00:55, Ankit Agarwal <an...@gmail.com> wrote:
> 
> Hi,
> When i try to covert pdf to image then for some pdfs i get a "out of
> memory" error. So i increased heap size and then i again got the error for
> some different pdf file.
> for the time being assume I have no memory leak from other objects. So what
> would be the reason for this memory out of error?
> Would it be just that the image is so large(which is not the case i think)
> that it consumes heap, or maybe pdfbox stores buffered image of each pages
> in its memory and this contributes to the growing heap size?
> Any insight would be wonderful.

Usually it’s because the PDF contains a compressed image which is very large
when decompressed. So the file isn’t big on disk, but it is in memory. Try using
a 32-bit JVM as these use less memory. 1GB of heap is usually enough but you
can go larger.

— John
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org