[Resolved runtime only] EventHandler and GenericObjectPool makes Leaked Managed Shell on memory.

devsunnysideup

New member
Hello Opsive team,
I am the engineer responsible for optimization in our company.

I am currently investigating issues where native wrapper instances for the managed shell fail to unload because instances in the managed shell are referencing native instances. (referred to as đź”—Leaked Managed Shell, will called LMS after of it)

During recent memory profiling, I discovered that resources present in the game and some dedicated type instances remained persistently in memory. Investigating these, I identified that static members of [Opsive.Shared.Events.EventHandler] and [Opsive.Shared.Utility.GenericObjectPool] were causing LMS.

1764918250336.png

Our project uses these to receive events emitted from [Opsive.Shared.Events.EventHandler] and calls [UnregisterEvent] to clean them up when they are destroyed(freed).

However, we discovered that LMS is generated because cache instances used in [GenericObjectPool] and similar static members do not perform null assignment when returned.

All this logic resides in precompiled DLLs. (Opsive.Shared.*.dll)
So, to address this on our end, we must either modify 'all' code using these features in assets, or, decompile it, insert logic to handle this issue, and recompile for use.

We want to resolve this issue.
 
Hello Justin,
I see. It's good news that it will be fixed in the next version.

This issue is particularly important because it prevents assets from being unloaded by ensuring the reference count for assets loaded and referenced dependently does not decrease. I would appreciate it if you could pay close attention to this point.

For our project, we are using Ultimate Inventory System version [1.2.20]. In this case, I am curious whether compatibility is guaranteed with the latest [Opsive.Shared.*.dll] libraries and their respective versions. dll libraries and whether compatibility with this version is guaranteed.

This is because even when I examine the metadata of the compiled dll, the assembly version appears as [0.0.0.0].

If Opsive has its own hosted NuGet source for managing these libraries, I would appreciate it if you could let me know.
 
Compatibility isn't guaranteed, but I believe that it will work with version 1.2.20.
 
Hello Justin,
Thank you for your quick response.

That sounds like good news.
In that case, could you tell me the deployment schedule for the patch that resolves this issue?

Even if not, it seems to be a separate pre-compiled DLL so if it becomes available, we'd like to receive it as soon as possible to verify whether the issue is actually resolved with new version.

The reason is that optimization work should not be judged as resolved prematurely without objective metrics (as it's easy to make incorrect judgments).
Therefore, we can confirm whether the issue is actually resolved by profiling a build incorporating the modified library, and we can also provide you with information on these results.

If it's okay with you, would it be possible to request your cooperation in this manner?
 
I don't have the built DLL yet due to some other dependencies but I am hoping to release this new version next week. I'll also try to build the DLL ahead of time and send it to you to try out but it'll depend on this other dependency for when I can build it.
 
Hello Justin,

It's been 3 days since you given some plan about this issue.
So if you don't mind then can we follow up how's going about progress?
 
Hello Justin, hope this reaching to you.

Just want to reminder that we've waiting for response about previous post.
If you having some delayed schedule then can we follow up that how's progressing about next release at least?

Wish that there's no problem around for preparing next update.
 
Hello, Justin.
We've just noticed that UIS just got an update yesterday, so imported new version of dlls directly in project and noticed that it can able to compiled by only changing [ResizeIfNecessary] extension method to explicitly call from [TypeUtility], we're running some scenario with new version, I'll update results soon.

Edit : We've confirmed new version of dlls are doing their job, it doesn't held event reference anymore.

Below comparison scenario is before entering in-game and then after return to title.

Before :
1766479877083.png

After :
1766479887672.png
 
Last edited:
Update : Despite clearly anticipating it, I overlooked the fact that the editor functionality would be incompatible.
When opening the editor (Manager Window), the following exception log appears, and we are currently looking a solution.

Code:
The serialized array of [SerializeReference] objects is missing entry for Refid 765923309773914113

The serialized array of [SerializeReference] objects is missing entry for Refid 765923309773914116

The serialized array of [SerializeReference] objects is missing entry for Refid 765923309773914115

The serialized array of [SerializeReference] objects is missing entry for Refid 765923309773914114

MissingMethodException: Method not found: object Opsive.Shared.Utility.Serialization.DeserializeFields(Opsive.Shared.Utility.MemberVisibility,System.Func`3<System.Type, object, object>)
Opsive.Shared.Editor.UIElements.Managers.MainManagerWindow.OnEnable () (at <c9e7e863283245faac2ba81b51b07b11>:0)
Opsive.UltimateInventorySystem.Editor.Managers.InventoryMainWindow.OnEnable () (at Assets/Opsive/UltimateInventorySystem/Editor/Managers/InventoryMainWindow.cs:222)
UnityEditor.EditorWindow:GetWindow(Boolean, String)
Opsive.UltimateInventorySystem.Editor.Managers.InventoryMainWindow:ShowWindow() (at Assets/Opsive/UltimateInventorySystem/Editor/Managers/InventoryMainWindow.cs:83)
(...)

MissingMethodException: Method not found: object Opsive.Shared.Utility.Serialization.DeserializeFields(Opsive.Shared.Utility.MemberVisibility,System.Func`3<System.Type, object, object>)
Opsive.Shared.Editor.UIElements.Managers.MainManagerWindow.OnEnable () (at <c9e7e863283245faac2ba81b51b07b11>:0)
Opsive.UltimateInventorySystem.Editor.Managers.InventoryMainWindow.OnEnable () (at Assets/Opsive/UltimateInventorySystem/Editor/Managers/InventoryMainWindow.cs:222)
 
*I attempted to edit a previous post to add content, but due to an internal server error, I have added it as a new post, apologize for any inconvenience.

Looking for replacing current version of entire Shared library to new version, but it seems like brings huge amounts of refactor base UIS codes too so we concluded to don't do it this way.
Hope that there's source code for it for UIS 1.2.20 that usable for just embedding into project or we will have looking for way to modification of these libraries for resolving this leak.
 
@Justin Hey Justin,
We are currently preparing for the mastering phase.

We discovered that we missed this issue while performing additional optimizations.
Currently, we are unable to update to the latest version because we have locked the version.
To resolve this issue simply, would it be acceptable to directly modify the DLL? (Opsive.Shared.Events.dll)

I look forward to a quick response if possible.
 
Yes, that's no problem. Have you guys announced the project that is using UIS? We'd love to see it
 
Back
Top