高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
【转帖】what Do I Need To Release
what do i need to release
what do i need to release
i have the following members in my class:
odstaticrxobject<qsservices> m_svcs;
oddbdatabaseptr m_pdb;
oddbobjectid m_layerid;
oddb3dpolylineptr m_p3dpl;
i set m_layerid to zero before writing out the file.
i set m_p3dpl to null after each call to appendoddbentity()
do i need to do anything with the other two?
am i doing the right thing?
it would be more correct to put members like oddb3dpolylineptr m_p3dpl;to some separate class and destruct object of the class before writing the file. you don't need to do anything with two others.
sincerely yours,
george udov
yes, that is correct.
do you still receive the exception?
maybe you could narrow down your problem to some complete sample and post it here?
vladimir
also, please check do you always use smartpointers?
for example, such code:
code:
oddbhatch* phatch = (oddbhatch*)pent->queryx(oddbhatch::desc());
can be reason of unclosed object. correct one is
code:
oddbhatchptr phatch = pent->queryx(oddbhatch::desc());
sincerely yours,
george udov
simple exception
i am hitting the second catch, int i = 2; so destruction of either the qsservices (modeled after the exservices example), or oddbdatabaseptr must be triggering the exception.
try
{
// for correct unicode translation apply the current system locale
setlocale(lc_all, "");
// but use usual conversion for scanf()/sprintf()
setlocale(lc_numeric, "c");
odstaticrxobject<qsservices> svcs;
oddbdatabaseptr pdb;
odinitialize(&svcs);
pdb = svcs.createdatabase(true);
m_filename = "c:\\dan.dwg";
try
{
odstreambufptr fb = svcs.createfile(
m_filename.c_str(),
oda::kfilewrite,
oda::ksharedenyno,
oda::kcreatealways);
pdb->writefile(fb, oddb::kdwg, oddb::vac18, false );
}
catch (...)
{
int i = 1;
}
oduninitialize();
}
catch (...)
{
int i = 2;
}
database should be released prior to oduninitialize()
vladimir
if i release the db before oduninitialize
if i release the db before oduninitialize i get:
exception c0000005 access violation read of address 0xc2c2c2d6
the only change i made was to add the line pdb->release();
call stack:
odsmartptr<oddbdatabase>::release
odsmartptr<oddbdatabase>::~odsmartptr<oddbdatabase >
do not call pdb->release(), this way you decrement object reference counter, and in smart pointer destructor, object wiil be deleted second time.
to release database (or any other object, owned by smart pointer) assign 0 to smart pointer, or create the pointer in local scope, to be destroyed at scope exit.
about smart pointer mechanics you may read for example in
"modern c++ design" by andrei alexandrescu
vladimir
|