fixed the function which is used when object is released