I am using PdfRenderer
in my app. In this app a user can open a PDF file and browse it. He can open another PDF file in the same session.
I just noticed, that I don't close it at all after use or before opening a new PDF. I just do the following:
mPdfRenderer = new PdfRenderer(mFileDescriptor);
In the Google example though the PdfRenderer is always closed after use.
if (null != mCurrentPage)
mCurrentPage.close();
mPdfRenderer.close();
mFileDescriptor.close();
Is it important to call close()
before opening a new PDF?
NOTE: This is a general answer will cover all the scenarios including yours
Well in general practice, you need to free up resources that are bound to your task, to be more precise
Non-preemptive
resources, it is considered to be best practice but, to remove the worker thread from the pool isn't extremely crucial nowadays, In short, for your answerGarbage Cleaner
will do your task for you when there will be a need of resources, or when the cleanup is scheduledWhen to Clean Resources or Close
worker Threads
onPause()
, your application for a moment (considered to be best practice but most developers don't do that, because some times, those process may take more resources on restarting because of a bundle processing[many processes may start ononStart()
])for your question's answer, I hope the above statement might clarify everything.