Fixed possible memory leak in SharedPtr (issue #287)