When I reach around 18 PDFViewPWF instances (each in a tab) I get an exception.

Question:
Here is the error I get

`

Message: bad allocation
Inner exception:
Stack trace:    at pdftron.PDF.PDFViewWPF.CreateTile(SByte* buffer, Int32 originX, Int32 originY, Int32 w, Int32 h, Int32 canvasNumber, Int64 cellNumber, Boolean finalRender, Boolean predictedRender, Int32 tiles_remaining, Boolean first_tile, Int32 canvas_width, Int32 canvas_height, Int32 cell_side_length, Int32 cell_per_row, Int32 cell_per_col, Int32 thumb_nail_id, Boolean swap_bytes, Int32 sequenceNumber)
   at pdftron.PDF.detail.CreateTile(Void* data, SByte* buffer, Int32 originX, Int32 originY, Int32 w, Int32 h, Int32 canvasNumber, Int64 cellNumber, Boolean finalRender, Boolean predictedRender, Int32 tiles_remaining, Boolean first_tile, Int32 canvas_width, Int32 canvas_height, Int32 cell_side_length, Int32 cell_per_row, Int32 cell_per_col, Int32 thumb_nail_id, Boolean swap_bytes)

`

How do I handle this?

Answer:
You need to use the following two functions to activate and deactivate your PDFViewWPF instances. Ideally just one is Active at any given time, to minimize memory usage.

PDFViewWPF.Deactivate()

PDFViewWPF.Activate()

When a PDFViewWPF goes out of view, you can call PDFViewWPF.Deactivate, and it release all memory except what is currently visible on the screen. Activate will subsequently resume the viewer, including pre-rendering content off screen. Using this should save you a lot of memory.

For example usage of these, see the PDFViewWPFTest sample, and how these functions are used in MainWindow.xaml.cs.