首页 > 解决方案 > 未释放 Native Collection,导致内存泄漏。分配自:在 Unity 修复中

问题描述

我在 Unity 中实现了 adMob 中介,其中集成了 inMobi 和 Unity 广告。但是我的游戏可以为 android 构建,但它一开始就崩溃(在显示 Unity 启动画面之后)。我怀疑这可能是因为警告正在发生内存泄漏(下面显示的全部内容)。它指向一个我从未编写过的代码,我之前也想出了一种启用完整堆栈跟踪的方法。

“未处置本机集合,导致内存泄漏。分配自:Unity.Collections.NativeArray`1:.ctor(Byte[], Allocator)”。

我试图解决这个问题,但我只知道你必须按照这个讨论对使用结构做一些网络请求https://answers.unity.com/questions/1830563/need-help-on-a-native-集合没有-disp.html。但我不清楚这个网络请求在哪里以及具体做什么。

警告:

A Native Collection has not been disposed, resulting in a memory leak. Allocated from:
Unity.Collections.NativeArray`1:.ctor(Byte[], Allocator)
UnityEngine.Networking.UploadHandlerRaw:.ctor(Byte[])
UnityEngine.Networking.UnityWebRequest:SetupPost(UnityWebRequest, WWWForm)
UnityEngine.Networking.UnityWebRequest:Post(String, WWWForm)
System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&)
System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)
System.Reflection.MethodBase:Invoke(Object, Object[])
Google.PortableWebRequest:StartRequest(HttpMethod, String, IDictionary`2, WWWForm) (at /Users/chkuang/Workspace/Git/unity-jar-resolver/source/VersionHandlerImpl/src/PortableWebRequest.cs:481)
Google.<StartRequestOnMainThread>c__AnonStorey6:<>m__C() (at /Users/chkuang/Workspace/Git/unity-jar-resolver/source/VersionHandlerImpl/src/PortableWebRequest.cs:443)
Google.RunOnMainThread:ExecuteNext() (at /Users/chkuang/Workspace/Git/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:486)
Google.RunOnMainThread:<ExecuteAllUnnested>m__12() (at /Users/chkuang/Workspace/Git/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:536)
Google.RunOnMainThread:RunAction(Action) (at /Users/chkuang/Workspace/Git/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:343)
Google.RunOnMainThread:ExecuteAllUnnested(Boolean) (at /Users/chkuang/Workspace/Git/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:530)
Google.RunOnMainThread:ExecuteAll() (at /Users/chkuang/Workspace/Git/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:512)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

我之前启用了 multidex,但我不明白有什么问题?

标签: unity3dmemory-leakscrash

解决方案


推荐阅读