Skip to content

Instantly share code, notes, and snippets.

@GrahamBorland
Created October 29, 2019 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GrahamBorland/f4b9e92ed0df2b0fbe2b1e8453c4f4ed to your computer and use it in GitHub Desktop.
Save GrahamBorland/f4b9e92ed0df2b0fbe2b1e8453c4f4ed to your computer and use it in GitHub Desktop.
Helper functions for memory management with J2V8
/**
* This executes the supplied lambda in the scope of a J2V8 MemoryManager, ensuring that all
* V8Object instances allocated in the scope are cleaned up on exit.
*/
inline fun <T> V8.scope(body: () -> T) : T {
val scope = MemoryManager(this)
try {
return body()
} finally {
scope.release()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment