Example #1
0
/// Perform shutdown of the Asset system.
///
/// This releases all final references to objects and releases all allocated memory.  This should be called during
/// the shutdown process after all types have been unregistered as well as after calling AssetType::Shutdown().
///
/// @see AssetType::Shutdown()
void Asset::Shutdown()
{
	HELIUM_TRACE( TraceLevels::Info, TXT( "Shutting down Asset system.\n" ) );
	
#if !HELIUM_RELEASE
	size_t objectCountActual = sm_objects.GetUsedSize();
	if( objectCountActual != 0 )
	{
		HELIUM_TRACE(
			TraceLevels::Error,
			TXT( "%" ) PRIuSZ TXT( " asset(s) still referenced during shutdown!\n" ),
			objectCountActual );

		size_t objectCount = sm_objects.GetSize();
		for( size_t objectIndex = 0; objectIndex < objectCount; ++objectIndex )
		{
			if( !sm_objects.IsElementValid( objectIndex ) )
			{
				continue;
			}

			Asset* pObject = sm_objects[ objectIndex ];
			if( !pObject )
			{
				continue;
			}
			
#if HELIUM_ENABLE_MEMORY_TRACKING
			Helium::RefCountProxy<Reflect::Object> *pProxy = pObject->GetRefCountProxy();
			HELIUM_ASSERT(pProxy);

			HELIUM_TRACE(
					TraceLevels::Error,
					TXT( "   - 0x%p: %s (%" ) PRIu16 TXT( " strong ref(s), %" ) PRIu16 TXT( " weak ref(s))\n" ),
					 pProxy,
					( pObject ? *pObject->GetPath().ToString() : TXT( "(cleared reference)" ) ),
					pProxy->GetStrongRefCount(),
					pProxy->GetWeakRefCount() );
#else
			HELIUM_TRACE( TraceLevels::Error, TXT( "- %s\n" ), *pObject->GetPath().ToString() );
#endif
		}
	}
#endif  // !HELIUM_RELEASE

	sm_objects.Clear();
	sm_wpFirstTopLevelObject.Release();

	delete sm_pNameInstanceIndexMap;
	sm_pNameInstanceIndexMap = NULL;

	delete sm_pEmptyNameInstanceIndexMap;
	sm_pEmptyNameInstanceIndexMap = NULL;

	delete sm_pEmptyInstanceIndexSet;
	sm_pEmptyInstanceIndexSet = NULL;

	sm_serializationBuffer.Clear();
}