ModeShape/modeshape — pull request #248 by rhauch (2011-12-16 23:29:24+00:00)
Title: MODE-1348 Export changed to limit memory consumption with large binary values

Exporting a workspace that has a lot of large binary values can result in out-of-memory errors, since the binary values are held in memory. (See MODE-1346 for improvements within the 3.x codebase.) While it'd be very difficult to change how the binary values are handled in 2.x, it should still be possible to modify the export logic to prevent holding all workspace content in-memory.

Therefore, the following changes were made to the export process:

1) After every Binary value on an _unmodified_ property is exported, that binary value is purged from memory and allowed to be garbage collected. Note this makes the binary values unusable (see step 2).
2) At the end of the export, the node that was exported is refreshed while keeping any transient changes, throwing out of the session's cache all _unmodified_ property values (including the binary values that were purged in step 1).

Note that the above steps only apply to _unmodified_ properties. This is very often the case, as a new session is used to export persisted content from the workspace. However, sessions _with transient changes_ can be exported, which is why the two steps listed above only purge binary values on _unmodified_ properties.

All unit and integration tests pass with these changes.