- Home /
Remote Config Native Collection memory leak
Windows 10, Unity 2021.1.15f1, Remote Config 2.0.1, Android Build Target
I call Remote Config Fetch on Awake once on startup and it throws the error "A Native Collection has not been disposed, resulting in a memory leak. Allocated from: Unity.Collections.NativeArray`1:.ctor(Byte[], Allocator)"
It appears to occur here in ConfigManagerImpl:
request.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(jsonText));
Here is the full stack trace obtained using the Jobs package with Full Stack Traces:
[Error] A Native Collection has not been disposed, resulting in a memory leak. Allocated from:
Unity.Collections.NativeArray`1:.ctor(Byte[], Allocator)
ConfigManagerImpl.DoRequest() at Library\PackageCache\com.unity.remote-config-runtime@1.0.1\Runtime\ConfigManagerImpl.cs:267
265: request.SetRequestHeader(header.key, header.value);
266: }
-->267: request.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(jsonText));
268: request.downloadHandler = new DownloadHandlerBuffer();
269: request.SendWebRequest().completed += (AsyncOperation op) => {
ConfigManagerImpl.PostConfig() at Library\PackageCache\com.unity.remote-config-runtime@1.0.1\Runtime\ConfigManagerImpl.cs:204
202: {
203: var jsonText = PreparePayload(userAttributes, appAttributes);
-->204: DoRequest(jsonText);
205: }
ConfigManagerImpl.FetchConfigs() at Library\PackageCache\com.unity.remote-config-runtime@1.0.1\Runtime\ConfigManagerImpl.cs:188
186: public void FetchConfigs<T, T2>(T userAttributes, T2 appAttributes) where T : struct where T2 : struct
187: {
-->188: PostConfig(userAttributes, appAttributes);
189: }
ConfigManager.FetchConfigs() at Library\PackageCache\com.unity.remote-config-runtime@1.0.1\Runtime\ConfigManager.cs:96
94: public static void FetchConfigs<T, T2>(T userAttributes, T2 appAttributes) where T : struct where T2 : struct
95: {
-->96: _configmanagerImpl.FetchConfigs(userAttributes, appAttributes);
97: }
ConfigFetcher.Fetch() at Assets\Scripts\Common\Utilities\ConfigFetcher.cs:55
54: IsFetching = true;
-->55: ConfigManager.FetchConfigs<UserAttributes, AppAttributes>(new UserAttributes(), new AppAttributes());
56: }
ConfigFetcher.Awake() at Assets\Scripts\Common\Utilities\ConfigFetcher.cs:34
32: ConfigManager.SetEnvironmentID(_environmentId);
33: ConfigManager.FetchCompleted += ApplyRemoteSettings;
-->34: Fetch();
35: }
36: else if (this != Instance)
Object.Internal_CloneSingleWithParent()
Object.Instantiate()
Object.Instantiate()
Object.Instantiate()
PersistentObjectsInstantiator.Awake() at Assets\Scripts\Common\PersistantObjects\PersistentObjectsInstantiator.cs:27
25: }
26: DontDestroyOnLoad(gameObject);
-->27: _presistentObjects = Instantiate(PersistentObjects, transform);
28: }
29: else if (this != _instance)
Any idea how to fix this?
Are you 100% positive there is no ConfigFetcher
duplicates and/or ConfigManager.FetchConfigs
cannot be called twice from elsewhere?
@andrew-lukasik Yes 100% sure, I set a break point now and it is only called once from Awake. I suspect the issue is UploadHandlerRaw is not wrapped inside a using statement.
Side note: call stack says this is com.unity.remote-config-runtime@1.0.1
but you wrote it's Remote Config 2.0.1
. Probably a typo.
@andrew-lukasik Yeah I did notice that but it isnt a typo, the package manager says Remote Config Release 2.0.1. I looked at the package file inside Remote Config, it says Version 2.0.1, then underneath inside dependences it says (com.unity.nuget.newtonsoft-json = 2.0.0) & (com.unity.remote-config-runtime = 1.0.1)
Here is a source of this specific allocation: https://github.com/needle-mirror/com.unity.remote-config-runtime/blob/b8f3e1ed794f7e8ac18c9134bf8e830b889969df/Runtime/ConfigManagerImpl.cs#L267
This UploadHandlerRaw exposes a manual Dispose
method but disposeUploadHandlerOnDispose is supposed to take care of that (it's set to true
by default according to doc page).
If you see this warning message once per run only and remote config works besides that just fine - then I wouldn't worry about it and move on to more important things.
But if this brakes your application then idk, tough one to diagnose. You can ask devs directly on dedicated unity forum too.
My issue is that it doesn't throw a warning but rather an error, I never ignored errors before :) Yes the application runs and retrieves the value, at least in the editor.