![]() |
【转帖】[arx]向当前数据库插入图块代码,有点问题,内存泄漏,各位看看
[arx]向当前数据库插入图块代码,有点问题,内存泄漏,各位看看
[arx]向当前数据库插入图块代码,有点问题,内存泄漏,各位看看 void hyd_insertblock2cur(acdbdatabase* psourcedb,cstring blockname) { cmemorystate oldmemstate, newmemstate, diffmemstate; oldmemstate.checkpoint(); acdocmanager->lockdocument(acdocmanager->curdocument()); //写当前数据库之前一定要锁定 acdbblocktable* psouretable=null; acdbobjectid idblock; psourcedb->getsymboltable(psouretable, acdb::kforread); if (psouretable->getat(blockname,idblock)== acad::eok)//指定文件找到块 { psouretable->close(); acdbdatabase * poutputdb = new acdbdatabase(adesk::ktrue); psourcedb->wblock(poutputdb, idblock); if (acdbcurdwg()->insert(idblock,blockname,poutputdb,true) != acad::eok) { delete poutputdb; poutputdb=null; return ; } delete poutputdb; poutputdb=null; acdbblocktablerecord* pmodelspace = null; acdbblocktable* pcurblocktable=null; if (acdbcurdwg()->getsymboltable(pcurblocktable, acdb::kforread)!=acad::eok) { return ; } if (pcurblocktable->getat(acdb_model_space,pmodelspace,acdb::kforwrite)!=acad::eok) { pcurblocktable->close(); return ; } if (pcurblocktable->getat(blockname,idblock)!=acad::eok) { pcurblocktable->close(); pmodelspace->close(); return ; } pcurblocktable->close(); acgescale3d scale; scale[x]=1; scale[y]=1; scale[z]=1; acgepoint3d basepoint; int retcode; acedinitget(null, null); acedalert("选择插入点!"); retcode = acedgetpoint(null, null,asdblarray(basepoint)); switch(retcode) { case rtcan : case rtnone : basepoint.set(0.0, 0.0, 0.0); break; case rtnorm : break; case rterror : break; } acdbblockreference *pbr = new acdbblockreference; pbr->setblocktablerecord(idblock); pbr->setposition(basepoint); pbr->setrotation(0); pbr->setscalefactors(scale); if (pmodelspace->appendacdbentity(pbr)!=acad::eok) { delete pbr; pmodelspace->close(); return ; } pbr->close(); pmodelspace->close(); } else psouretable->close(); acdocmanager->unlockdocument(acdocmanager->curdocument()); //解除锁定 trace0("\n\ninsert is finishing!!\n\n"); newmemstate.checkpoint(); if( diffmemstate.difference( oldmemstate, newmemstate ) ) { trace( "memory leaked!\n" ); } // 输出内存泄漏报告,显示在 output 窗口的 debug 页中 _crtdumpmemoryleaks(); } 我自己实在是检查不出来了。在cad中反复操作插入图块都是好的,可是一关掉cad,等一会就跳出了一个警告框了。估计是cad关掉后,清理内存时,有申请的内存没有卸载掉的,各位帮忙看看吧 昏..多半是因为你用memory check的原因..我的意思是内存泄漏是由内存检查本身的存在引起的..因为release build对debug build兼容不好.. acad软件本身是release build, 所以arx也要尽量用release build, 避免不必要的debug和release不兼容的麻烦.. virtue is like a rich stone, best plain set. -- francis bacon, <of beauty> |
| 所有的时间均为北京时间。 现在的时间是 04:59 PM. |