---
title: "Using document efficiently"
canonical_url: "https://www.nutrient.io/guides/ios/getting-started/using-document-efficiently/"
md_url: "https://www.nutrient.io/guides/ios/getting-started/using-document-efficiently.md"
last_updated: "2026-05-23T00:08:18.103Z"
description: "Learn to optimize document management by efficiently reusing `Document` objects, leveraging caching strategies, and ensuring unique identifiers for improved performance."
---

Creating a [`Document`](https://www.nutrient.io/api/ios/documentation/pspdfkit/document) is cheap, but accessing its various properties might require expensive PDF parsing. So it’s a good idea to keep `Document`s around to avoid the expense of recreating them whenever necessary.

Don’t create a [`Document`](https://www.nutrient.io/api/ios/documentation/pspdfkit/document) in code like `collectionView:cellForItemAtIndexPath:`, but instead keep a dictionary or other data structure around that can create these documents as needed and then return the same object when you need to access it again. This will improve performance a lot. Using `NSCache` with the [`UID`](https://www.nutrient.io/api/ios/documentation/pspdfkit/document/uid)s as keys and the documents as objects is ideal.

If you already have a way to identify your documents uniquely, use this and set the [`UID`](https://www.nutrient.io/api/ios/documentation/pspdfkit/document/uid) property to your unique string. If you don’t set `UID`, Nutrient will automatically extrapolate a `UID` based on the file URL and possibly the content. This process might be a bit expensive, so manually setting the `UID` is a good idea — if you already have such a system in place. If not, let Nutrient do its thing and don’t worry too much.

If you create [`Document`](https://www.nutrient.io/api/ios/documentation/pspdfkit/document) objects in a tight loop, add an `@autoreleasepool` so objects can be deallocated early. If you edit annotations or use the Document Editor, make sure there’s only one document instance where you edit. Nutrient automatically saves the document, and keeping multiple independent copies of the document around, all of which save to the file, might overwrite or discard changes.

For more details on saving, file coordination, and reopening the same document over time, refer to [using automatic saving safely](https://www.nutrient.io/guides/ios/best-practices/using-automatic-saving-safely.md).

Loading a `Document` from data in memory using [`DataContainerProvider`](https://www.nutrient.io/api/ios/documentation/pspdfkit/datacontainerprovider) isn’t recommended. Since iOS is an environment without virtual memory, allocating more memory than is available by loading a large PDF will get your app terminated by iOS. Additionally, Nutrient is unable to automatically save annotation changes back into a PDF when using data in memory. If you want to use data in memory because of encryption, look into [`AESCryptoDataProvider`](https://www.nutrient.io/api/ios/documentation/pspdfkit/aescryptodataprovider) or a custom implementation of [`DataProviding`](https://www.nutrient.io/api/ios/documentation/pspdfkit/dataproviding) to dynamically decrypt the needed portions of the PDF.
---

## Related pages

- [Advanced Carthage integration](/guides/ios/miscellaneous/advanced-carthage-integration.md)
- [Advanced CocoaPods integration](/guides/ios/miscellaneous/advanced-cocoapods-integration.md)
- [Airdrop](/guides/ios/features/airdrop.md)
- [App Transport Security](/guides/ios/pspdfkit-instant/app-transport-security.md)
- [Bitcode](/guides/ios/faq/bitcode.md)
- [Carthage integration](/guides/ios/best-practices/carthage-integration.md)
- [Framework Size](/guides/ios/faq/framework-size.md)
- [Customizing The Page Number](/guides/ios/customizing-pdf-pages/customizing-the-page-number.md)
- [Optimize PDF documents for mobile rendering on iOS](/guides/ios/miscellaneous/optimize-pdf-documents-for-mobile-rendering.md)
- [Nightly Builds](/guides/ios/best-practices/nightly-builds.md)
- [Powered By Nutrient](/guides/ios/miscellaneous/powered-by-nutrient.md)
- [Customizing the log level on iOS](/guides/ios/features/logging.md)
- [Modifying permissions in your iOS app](/guides/ios/getting-started/permissions.md)
- [iOS PDF SDK security](/guides/ios/faq/sdk-security.md)
- [Strategies For Multiple Bundle Ids](/guides/ios/faq/strategies-for-multiple-bundle-ids.md)
- [Third Party Compatibility](/guides/ios/miscellaneous/third-party-compatibility.md)
- [Transferring File Edits To A Server](/guides/ios/best-practices/transferring-file-edits-to-a-server.md)
- [Saving Data Externally](/guides/ios/memory-and-storage/saving-data-externally.md)
- [Youtube Links](/guides/ios/miscellaneous/youtube-links.md)
- [Version Numbering](/guides/ios/best-practices/version-numbering.md)
- [Using Automatic Saving Safely](/guides/ios/best-practices/using-automatic-saving-safely.md)
- [Manage your iOS status bar with view controllers](/guides/ios/faq/view-controller-based-status-bar-appearance.md)
- [About Memory Usage](/guides/ios/memory-and-storage/about-memory-usage.md)
- [Reduce App Size](/guides/ios/best-practices/reduce-app-size.md)

