将delete
所有指向对象的指针重置为NULL
. 此外,您不应更改 Windows DEBUG 运行时的默认内存填充,并且您应该boost::shared_ptr<>
以任何方式使用指针之类的东西。
也就是说,如果你真的想在脚上开枪,你可以。
您可以使用这样的分配器挂钩来更改Windows DEBUG 运行时的默认填充。这仅适用于 HEAP 分配的对象!
int main(int argc,char** arv)
{
// Call first to register hook
_CrtSetAllocHook(&zero_fill);
// Do other stuff
malloc(100);
}
int zero_fill(int nAllocType,
void* pvData,
size_t nSize,
int nBlockUse,
long lRequest,
const unsigned char *szFileName,
int nLine )
{
/// Very Importaint !!
/// infinite recursion if this is removed !!
/// _CRT_BLOCK must not do any thing but return TRUE
/// even calling printf in the _CRT_BLOCK will cause
/// infinite recursion
if ( nBlockUse == _CRT_BLOCK )
return( TRUE );
switch(nAllocType)
{
case _HOOK_ALLOC:
case _HOOK_REALLOC:
// zero initialize the allocated space.
memset(pvData,0,nSize);
break;
case _HOOK_FREE:
break;
}
return TRUE;
}