Memory management through JavaScript