fix memory implementation issue when running as javascript. Transaction
was closed too early