高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
【转帖】oddbdatabasenumrefs90 and oddbdatabaserelease90 problem
oddbdatabase::numrefs() and oddbdatabase::release() problem
oddbdatabase::numrefs() and oddbdatabase::release() problem
hi,
i have a class drawing which is exported to outer libraries from a dll.
it is an encapsulation of a oddbdatabase - i have a member oddbdatabase* m_pdrw; (the outer libraries are not connected with dwgdirect).
i want to create an instance of the oddbdatabase at construction and to delete it on destruction of the drawing class.
what code should i use in order to escape having a smart ptr as member?
let's take this code:
oddbdatabaseptr pdb = theapp.services()->createdatabase();
m_pdrw = pdb.detach();
why m_pdrw->numrefs() returns 2?
and then calling m_pdrw->release() cause the m_pdrw variable to be deleted, though the reference counting should be made to 1!
what wrong am i doing?
thanks in advance for any help.
regards
chudomir
hi
from the header file detach() is described as follows:
returns a pointer to the object referenced by this smart pointer, and
gives up this smart pointer's reference to the object. the object's reference
count is not modified.
use release().
thank you for your reply, walt,
the problem is that
"oddbdatabaseptr pdb = theapp.services()->createdatabase();
_assert(pdb->numrefs()==2);
pdb->release();"
just deletes the database object.
that's why i use detaching.
regards
chudomir
|