Hi Robert, Cory, I implement some weeks before a memory leak detector for VS 2005 and cleaned up the code that all of my objects get right removed from memory now, espacially i had some bad behaviour before cleaning up my webbased rendering plugin, after removing all memory leak even quicktime get closed without any crashes. so it's really important that all allocated memory gets fine removed. the plugin don't have some leaks coming through the OSG core, and believe me: our application is much more complex than just use some geometry nodes. and i can say that the osg core should be free of any memory leak, i suggest using in all user application the ref_ptr concept which robert is using in the core of osglib then you don't get some leaks. I also believe that there is also many false positives...
Here is the code you should use : // memory leak check ... ----------------------------------------------------------------------------------------------------------------------------------------------- MEM_LEAK_BASE.h ----------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------- Just include this in each CPP file #ifdef MEM_LEAK_CHK #include "DbgMemoryImpl.h" #endif ----------------------------------------------------------------------------------------------------------------------------------------------- i hope this works also ................ /adrian 2009/1/30 Robert Osfield <[email protected]> > Hi Cory, > > I believe the are bugs in the memory tracking support in VS, > especially when using MFC, that produce many false positives. You'll > need to get more info about this from VS experts though, the last time > I used VS was in the last Century! > > Robert. > > On Fri, Jan 30, 2009 at 3:32 PM, Cory Riddell <[email protected]> wrote: > > After my (MFC) app ends, the output window in Visual Studio fills with a > > bunch of this: > >> > >> Detected memory leaks! > >> Dumping objects ->{164} normal block at 0x02A54248, 128 bytes long. > >> Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > 00 > >> {163} normal block at 0x02A541A8, 96 bytes long. > >> Data: < c > F8 87 63 01 00 00 00 00 01 00 00 00 00 00 00 > 00 > >> {161} normal block at 0x02A54068, 64 bytes long. > >> Data: <OpenThread v1.2p> 4F 70 65 6E 54 68 72 65 61 64 20 76 31 2E 32 > 70 > > > > I'm just getting started with OSG. I'm using it to render geometry from > > Granite (the geometry kernel from the Pro/ENGINEER people, just getting > > started with this too). Both libraries have their own reference counted > > pointer types and they function a bit differently so I'm probably just > > abusing one or the other. > > > > Normally I can just pick one of the allocation numbers from the dump > (161, > > 163, and 164 above) and tell the debugger to stop there, but for some > reason > > that isn't working. If I have time later today, I'm going to instrument > > everything with BoundsChecker and run it again. > > > > Cory > > > > > > On Fri, Jan 30, 2009 at 9:08 AM, Robert Osfield < > [email protected]> > > wrote: > >> > >> Hi Cory, > >> > >> The OSG users ref counting, so if all external references to the scene > >> and viewer are removed then all the associated resources should be > >> deleted automatically. If you app keeps any references to this data > >> then it'll stay around until these references are removed. > >> > >> If you've enabled caching in the osgDB::Registry then it can keep > >> around a reference for loaded objects in its cache, so clearing this > >> would be required. Also if you app loads OSG plugins as part of > >> loading your data then one could see this as items you might want to > >> unload. > >> > >> BTW, what makes you think that things aren't being released? > >> > >> Robert. > >> > >> On Fri, Jan 30, 2009 at 2:57 PM, Cory Riddell <[email protected]> > wrote: > >> > Is there a correct way to stop OSG and free all the resources that > have > >> > been > >> > acquired by without stopping the application? I thought that when my > >> > osgViewer::Viewer instance went out of scope, everything would be > >> > released, > >> > but that doesn't seem to be the case. > >> > > >> > cory > >> > > >> > _______________________________________________ > >> > osg-users mailing list > >> > [email protected] > >> > > >> > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > >> > > >> > > >> _______________________________________________ > >> osg-users mailing list > >> [email protected] > >> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > > > > > _______________________________________________ > > osg-users mailing list > > [email protected] > > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > > > > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > -- ******************************************** Adrian Egli
// ---------------------------------------------------------------------- // Adrian Egli (C) 2008-2009 <AS Software GmbH ; http://3d.assoftware.ch> // ---------------------------------------------------------------------- #define WEBADDONBASE_LIBRARY //all implementation files has to use the macros include (memory check, and much more features) #include "MLDBase.h" #include "DbgMemory.h" using namespace WebaddonBase; #ifdef MEM_LEAK_CHK #include "DbgMemoryImpl.h" #endif /////////////////////////////////////////////////////////////////////////// // static members int DbgMemory::s_InNewOperation_Guard_Flag = 0; int DbgMemory::s_BlocksAllocated = 0; std::string DbgMemory::s_LastMemoryOperationInfo; bool DbgMemory::s_Leak_Listening = false; ////////////////////////////////////////////////////////////////////////// // avoid compiler warning C4251 typedef std::map<void*,std::string> MemoryInfoMap; static MemoryInfoMap s_DbgMemory_MemoryInfoMap; ////////////////////////////////////////////////////////////////////////// int DbgMemoryAllocHook( int nAllocType, void * pvData, size_t nSize, int nBlockUse, long lRequest, const unsigned char * szFileName, int nLine ) { #ifdef _DEBUG #ifdef MEM_LEAK_CHK char *operation[] = { "", "allocating", "re-allocating", "freeing" }; char *blockType[] = { "Free", "Normal", "CRT", "Ignore", "Client" }; if ( nBlockUse == _CRT_BLOCK ) // Ignore internal C runtime library allocations return( 1 ); if ( nLine > 0 ) { WebaddonBase::DbgMemory::s_LastMemoryOperationInfo.clear(); char cFileName[1024]; WEBADDON_SPRINTF(cFileName,"%s",szFileName); char cLine[8]; WEBADDON_SPRINTF(cLine,"%i",nLine); WebaddonBase::DbgMemory::s_LastMemoryOperationInfo = cFileName; WebaddonBase::DbgMemory::s_LastMemoryOperationInfo += "@"; WebaddonBase::DbgMemory::s_LastMemoryOperationInfo += cLine; WebaddonBase::DbgMemory::s_LastMemoryOperationInfo += " {"; char cSize[8]; WEBADDON_SPRINTF(cSize,"%i",nSize); WebaddonBase::DbgMemory::s_LastMemoryOperationInfo += cSize; WebaddonBase::DbgMemory::s_LastMemoryOperationInfo += " bytes }"; } #endif #endif return( 1 ); // Allow the memory operation to proceed } ////////////////////////////////////////////////////////////////////////// DbgMemory::DbgMemory() { #ifdef _DEBUG #ifdef MEM_LEAK_CHK _CrtSetDbgFlag( _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_CRT_DF); #endif #endif } DbgMemory::~DbgMemory() { #ifdef _DEBUG #ifdef MEM_LEAK_CHK _CrtSetDbgFlag( _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_CRT_DF); #endif #endif } void DbgMemory::reportLeaks(){ if ( DbgMemory::s_Leak_Listening ) { std::cout << "-------------------------------------------------------------------------------------------------------"<< std::endl; std::cout << "Memory Leak Report ... [" << SVNVersion::getSVNVersion() << "]" << std::endl; std::cout << "-------------------------------------------------------------------------------------------------------"<< std::endl; int iCount=0; for (MemoryInfoMap::iterator it=s_DbgMemory_MemoryInfoMap.begin();it!=s_DbgMemory_MemoryInfoMap.end();it++) { std::cout << "{"<< ++iCount <<"}\t"<<it->first << " -> " << it->second << std::endl; } std::cout << "......................................................................................................."<< std::endl; std::cout << iCount << " leaks located \t"<< DbgMemory::s_BlocksAllocated << std::endl; std::cout << "-------------------------------------------------------------------------------------------------------"<< std::endl; } } bool DbgMemory::markFree(void* key){ if ( DbgMemory::s_Leak_Listening ) { MemoryInfoMap::iterator it=s_DbgMemory_MemoryInfoMap.find(key); if ( it!=s_DbgMemory_MemoryInfoMap.end() ) { s_DbgMemory_MemoryInfoMap.erase(it); return true; } return false; } return false; } bool DbgMemory::markAlloc(void* key,std::string info){ if ( DbgMemory::s_Leak_Listening ) { MemoryInfoMap::iterator it=s_DbgMemory_MemoryInfoMap.find(key); if ( it!=s_DbgMemory_MemoryInfoMap.end() ) { return false; } s_DbgMemory_MemoryInfoMap.insert(MemoryInfoMap::value_type(key,info)); return true; } return false; } void DbgMemory::enableLeakListening() { #ifdef _DEBUG #ifdef MEM_LEAK_CHK DbgMemory::s_Leak_Listening = true; _CrtSetAllocHook( DbgMemoryAllocHook ); #endif #endif } void DbgMemory::disableLeakListening() { #ifdef _DEBUG #ifdef MEM_LEAK_CHK _CrtSetAllocHook( NULL ); #endif #endif DbgMemory::s_Leak_Listening = false; }
// ---------------------------------------------------------------------- // Adrian Egli (C) 2008-2009 <AS Software GmbH ; http://3d.assoftware.ch> // ---------------------------------------------------------------------- #ifdef _DEBUG // We overwrite now the new and delete operator to get memory allocation / deallocation information // to store the information in a map. Then we are able to detect memory leaks.... #ifdef OVERWRITE_NEW_DELETE void *operator new( size_t stAllocateBlock, int blockType , const char* fileName, int line ) { void* ptr = _malloc_dbg( stAllocateBlock,blockType,fileName, line ); if ( !WebaddonBase::DbgMemory::s_InNewOperation_Guard_Flag ) { WebaddonBase::DbgMemory::s_InNewOperation_Guard_Flag = 1; WebaddonBase::DbgMemory::s_BlocksAllocated++; //std::cout << "A [" << WebaddonBase::DbgMemory::s_BlocksAllocated << "][" << ptr << "][" << stAllocateBlock << " bytes][" << WebaddonBase::DbgMemory::s_LastMemoryOperationInfo << "]" << std::endl ; WebaddonBase::DbgMemory::markAlloc(ptr,WebaddonBase::DbgMemory::s_LastMemoryOperationInfo); WebaddonBase::DbgMemory::s_InNewOperation_Guard_Flag = 0; } return ptr; } void operator delete( void *pvMem ) { static int fInOpDelete = 0; // Guard flag. if ( ! WebaddonBase::DbgMemory::s_InNewOperation_Guard_Flag ) { WebaddonBase::DbgMemory::s_InNewOperation_Guard_Flag = 1; WebaddonBase::DbgMemory::s_BlocksAllocated--; //std::cout << "D [" << WebaddonBase::DbgMemory::s_BlocksAllocated << "][" << pvMem << "]" << std::endl ; WebaddonBase::DbgMemory::markFree(pvMem); WebaddonBase::DbgMemory::s_InNewOperation_Guard_Flag = 0; } free( pvMem ); } #endif #define new new(_CLIENT_BLOCK,__FILE__,__LINE__) #endif
// ---------------------------------------------------------------------- // Adrian Egli (C) 2008-2009 <AS Software GmbH ; http://3d.assoftware.ch> // ---------------------------------------------------------------------- // this is the global macros definition for the Webaddon SDK #ifndef WEBADDON_DBG_MEMORY_H #define WEBADDON_DBG_MEMORY_H #include "WebaddonBase/WebaddonBase_exports.h" #include <map> #include <string> namespace WebaddonBase { class WEBADDONBASE_EXPORT DbgMemory { public: DbgMemory(); ~DbgMemory(); static void reportLeaks(); static bool markFree(void* ptr); static bool markAlloc(void* ptr,std::string info); static void enableLeakListening(); static void disableLeakListening(); public: static int s_InNewOperation_Guard_Flag; static int s_BlocksAllocated; static std::string s_LastMemoryOperationInfo; static bool s_Leak_Listening; }; } #endif
// ---------------------------------------------------------------------- // Adrian Egli (C) 2008-2009 <AS Software GmbH ; http://3d.assoftware.ch> // ---------------------------------------------------------------------- #ifndef MLDBASE_H___ #define MLDBASE_H___ // *********************************** // Needs : Visual Studio 2005 : c++ // IF DEFINED -> ENABLE MEM LEAK CHECK // *********************************** #define MEM_LEAK_CHK // *********************************** // include our debug memory class #include "DbgMemory.h" #ifdef _DEBUG #ifndef DEBUG #define DEBUG #endif #ifdef WIN32 // include and enable memory leak check (CRTDBG) #ifdef MEM_LEAK_CHK #define _CRTDBG_MAP_ALLOC 1 #define _CRTDBG_MAP_ALLOC_NEW 1 #include <winsock2.h> #include <stdlib.h> #include <crtdbg.h> #define DEBUG_MEMORY WebaddonBase::DbgMemory _dbgMemory; #endif #endif #endif #ifndef DEBUG_MEMORY #define DEBUG_MEMORY #endif #endif
// ---------------------------------------------------------------------- // Adrian Egli (C) 2008-2009 <AS Software GmbH ; http://3d.assoftware.ch> // ---------------------------------------------------------------------- // Just include this in each CPP file #ifdef MEM_LEAK_CHK #include "DbgMemoryImpl.h" #endif
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

