Archived
is it legal to put something derived from IceUtil::Shared on the stack
hi.
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++.
raphael
Comments
-
Hi Raphael,
The heap allocation of class instances is described in the Ice Manual.
Ice expects that class instances you pass to Ice (through
Ptr
s) 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 adelete 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,
Bernard0