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? My suspicion is that UploadHandlerRaw is not wrapped inside a using statement.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.RemoteConfig;
//using com.ootii.Messages;
public class RemoteConfigManager : MonoBehaviour
{
public struct userAttributes { }
public struct appAttributes { }
private void Awake()
{
ConfigManager.FetchCompleted += ApplyRemoteSettings;
// Set the user’s unique ID:
//ConfigManager.SetCustomUserID("some-user-id");
// Set the environment ID:
//ConfigManager.SetEnvironmentID("an-env-id");
ConfigManager.FetchConfigs<userAttributes, appAttributes>
(new userAttributes(), new appAttributes());
}
void ApplyRemoteSettings(ConfigResponse configResponse)
{
// Conditionally update settings, depending on the response's origin:
switch (configResponse.requestOrigin)
{
case ConfigOrigin.Default:
Debug.Log("No settings loaded this session; using default values.");
break;
case ConfigOrigin.Cached:
Debug.Log("No settings loaded this session; using cached values from a previous session.");
break;
case ConfigOrigin.Remote:
//MessageDispatcher.SendMessage(GAMEEVENTS.EVT_REMOTE_SETTINGS_FETCH_COMPLETE, 1);
Debug.Log("New settings loaded this session; update values accordingly.");
//Debug.Log("Ball Speed : "+ ConfigManager.appConfig.GetFloat("ballspeed"));
//enemyVolume = ConfigManager.appConfig.GetInt("enemyVolume");
//enemyHealth = ConfigManager.appConfig.GetInt("enemyHealth");
//enemyDamage = ConfigManager.appConfig.GetFloat("enemyDamage");
//assignmentId = ConfigManager.appConfig.assignmentID;
break;
}
}
private void OnDestroy()
{
ConfigManager.FetchCompleted -= ApplyRemoteSettings;
}
//TESTING
private void Start()
{
//InvokeRepeating("Test", 10.0f, 10.5f);
}
void Test()
{
Debug.Log("Fetching again.");
ConfigManager.FetchConfigs<userAttributes, appAttributes>
(new userAttributes(), new appAttributes());
}
//TODO If Awake doesnt fetch a value then we might have to check again after some time to fetch fresh set of values
}
This is my code. I created a new scene with just a camera and a game object called RemoteConfigSettings manager and added this script to it. If you play 2-3 times you should see the error. Im using Mac.
I added debug statements but error occurs at end while exiting the play mode
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.RemoteConfig;
using com.ootii.Messages;
public class RemoteConfigManager : MonoBehaviour
{
public struct userAttributes { }
public struct appAttributes { }
private void Awake()
{
Debug.Log("A");
ConfigManager.FetchCompleted += ApplyRemoteSettings;
Debug.Log("B");
// Set the user’s unique ID:
//ConfigManager.SetCustomUserID("some-user-id");
// Set the environment ID:
//ConfigManager.SetEnvironmentID("an-env-id");
Debug.Log("C");
ConfigManager.FetchConfigs<userAttributes, appAttributes>
(new userAttributes(), new appAttributes());
Debug.Log("D");
}
void ApplyRemoteSettings(ConfigResponse configResponse)
{
// Conditionally update settings, depending on the response's origin:
switch (configResponse.requestOrigin)
{
case ConfigOrigin.Default:
Debug.Log("No settings loaded this session; using default values.");
break;
case ConfigOrigin.Cached:
Debug.Log("No settings loaded this session; using cached values from a previous session.");
break;
case ConfigOrigin.Remote:
Debug.Log("GAA");
MessageDispatcher.SendMessage(GAMEEVENTS.EVT_REMOTE_SETTINGS_FETCH_COMPLETE, 1);
Debug.Log("GBB");
Debug.Log("New settings loaded this session; update values accordingly.");
//Debug.Log("Ball Speed : "+ ConfigManager.appConfig.GetFloat("ballspeed"));
//enemyVolume = ConfigManager.appConfig.GetInt("enemyVolume");
//enemyHealth = ConfigManager.appConfig.GetInt("enemyHealth");
//enemyDamage = ConfigManager.appConfig.GetFloat("enemyDamage");
//assignmentId = ConfigManager.appConfig.assignmentID;
break;
}
}
private void OnDestroy()
{
Debug.Log("G");
ConfigManager.FetchCompleted -= ApplyRemoteSettings;
Debug.Log("H");
}
//TESTING
private void Start()
{
//InvokeRepeating("Test", 2.0f, 2.5f);
}
void Test()
{
Debug.Log("Fetching again.");
Debug.Log("E");
ConfigManager.FetchConfigs<userAttributes, appAttributes>
(new userAttributes(), new appAttributes());
Debug.Log("F");
}
//TODO If Awake doesnt fetch a value then we might have to check again after some time to fetch fresh set of values
}
In Play mode? So this only happens when running in the Editor, and not on a device? The original post mentioned Android as the target platform. What is “GetStacktrace(int)”
If I enable Full as shown below then “GetStacktrace(int)” appears in log messages trace
I have not tested it on device yet but my build target is set to iOS
Any updates? I’m still getting exceptions every time I run my app.
I actually know the solution, add IDisposable interface to RCUnityWebRequest and in ConfigManagerImpl.cs function DoRequest() wrap var request = new RCUnityWebRequest(); inside a using statement. I did it myself but everytime I run my game it resets the code since it is inside a unity package. Can you please update the package ASAP or let me know how to prevent my edits from being overwritten by unity?
We’re taking a look at this bug. In regards to your question to having a version of the package that will not be overwritten when you make a change to the code; I believe you can change the reference to the current installed version of the Remote Config package by referencing the local filesystem path and adding it locally from the Package Manager UI: https://docs.unity3d.com/Manual/upm-ui-local.html
Hi @wilczarz_84 don’t have anything to report currently. We will update on this forum thread when we have a patch you can apply, and expected release for a package containing the fix