| 115 | #endif |
| 116 | |
| 117 | void ReleaseObjects(bool gameOnly) |
| 118 | { |
| 119 | // Flush objects already enqueued objects to delete |
| 120 | ObjectsRemovalService::Flush(); |
| 121 | |
| 122 | // Give GC a try to cleanup old user objects and the other mess |
| 123 | MCore::GC::Collect(); |
| 124 | MCore::GC::WaitForPendingFinalizers(); |
| 125 | |
| 126 | // Destroy objects from game assemblies (eg. not released objects that might crash if persist in memory after reload) |
| 127 | const auto flaxModule = GetBinaryModuleFlaxEngine(); |
| 128 | _objectsLocker.Lock(); |
| 129 | for (auto i = _objectsDictionary.Begin(); i.IsNotEnd(); ++i) |
| 130 | { |
| 131 | auto obj = i->Value; |
| 132 | if (gameOnly && obj->GetTypeHandle().Module == flaxModule) |
| 133 | continue; |
| 134 | |
| 135 | #if USE_OBJECTS_DISPOSE_CRASHES_DEBUGGING |
| 136 | LOG(Info, "[OnScriptingDispose] obj = 0x{0:x}, {1}", (uint64)obj.Ptr, String(obj.TypeName)); |
| 137 | #endif |
| 138 | obj->OnScriptingDispose(); |
| 139 | } |
| 140 | _objectsLocker.Unlock(); |
| 141 | |
| 142 | // Release assets sourced from game assemblies |
| 143 | Array<Asset*> assets = Content::GetAssets(); |
| 144 | for (auto asset : assets) |
| 145 | { |
| 146 | if (asset->GetTypeHandle().Module == flaxModule) |
| 147 | { |
| 148 | continue; |
| 149 | } |
| 150 | |
| 151 | asset->DeleteObject(); |
| 152 | } |
| 153 | ObjectsRemovalService::Flush(); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | Delegate<BinaryModule*> Scripting::BinaryModuleLoaded; |
no test coverage detected