added a runtime limit to clean up after memory errors