Added ref counting to clean up js objects in unit tests