Skip to main content
Skip table of contents

Memory Management

Working with multiple pages

Often there is a requirement to iterate through the pages of a document where the content of the page needs to be read. Memory usage within Mako increases with each page read and for performance reasons, some of the memory is not automatically released when moving to the next page. As the number of pages in the document increases, the need to keeping memory usage low is beneficial or required. 

There are two methods of freeing memory that may help.

Releasing the page

Once a page's content has been read, some of the content will be cached. This can be released by calling IPage::release().

If a page is not edited, and the original source is available, the IPage's reference to the page content will be released. This is useful to release the memory associated with the page content if a page is not to be accessed again. The content may be safely requested again using getContent().

If the page content cannot be released, the call will be ignored.

If the page has been edited, it can be reverted first by calling IPage::revert() and then calling IPage::release().

This method should be the first port of call to reduce memory usage.

Code Example
CPP
  IDocumentPtr document = assembly->getDocument();
  uint32 pagecount = document->getNumPages();
  
  // Iterate the pages to get text runs
  for (uint32 pageIndex = 0; pageIndex < pagecount; pageIndex++)
  {
      IPagePtr page = document->getPage(pagenumber);
      CTextRunVect textruns;
      page->getTextRuns(textruns);
      // Release memory
      page->revert();
      page->release();
  }
C#
IDocument document = assembly.getDocument();
uint pagecount = document.getNumPages();
 
// Iterate the pages to get text runs
for (uint pageIndex = 0; pageIndex < pagecount; pageIndex++)
{
    IPage page = document.getPage(pageIndex);
    CTextRunVect textruns = page.getTextRuns(textruns);

    // Release memory
    page.revert();
    page.release();
}

Emptying Mako's cache

Mako's cache can be emptied by calling IJawsMako::freeMemory(). This can be used to inform Mako that system memory is being exhausted and will cause Mako to free up cached information and discard any unmodified pages.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.