This forum has been archived. Please start a new discussion on GitHub.

is it legal to put something derived from IceUtil::Shared on the stack

edited June 2017 in Help Center

i can remember reading some piece of information saying it is forbidden to put instances from classes derived from IceUtil::Shared on the stack.
of course i don't plan to then in any functions accepting a Handle since this would result in a double free.
now there is a situation where i need this, but i can't find this piece of information anywhere.
i tried it and nothing crashed (yet).
as far as i could see in the code, this should not be a problem.
so just to make sure i want to ask here.
i am using ice 3.5 on ubuntu 14 LTS and use c++.



  • bernard
    bernard Jupiter, FL

    Hi Raphael,

    The heap allocation of class instances is described in the Ice Manual.

    Ice expects that class instances you pass to Ice (through Ptrs) are allocated on the heap: Ice typically acquires a refcount on this object and later releases this refcount, which could result in the destruction of the object (through a delete this). You can also instruct your object to never delete itself with __setNoDelete.

    In case you don't use directly or indirectly the IceUtil::Shared refcounting, you can safely allocate your object on the stack even without calling __setNoDelete.

    Best regards,