Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native Collection has not been disposed, resulting in a memory leak. #29

Open
NachtgeistW opened this issue Apr 25, 2021 · 15 comments
Open
Labels
bug

Comments

@NachtgeistW
Copy link

@NachtgeistW NachtgeistW commented Apr 25, 2021

This happened in 2021.1. Every time I press "Play" button, they appear in console. I used com.unity.jobs and caught these:

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[])
WakaTime.Plugin:SendHeartbeat(Boolean) (at Library\PackageCache\com.vladfaust.unitywakatime@4dedbea\Editor\Plugin.cs:145)
WakaTime.Plugin:OnSceneClosing(Scene, Boolean) (at Library\PackageCache\com.vladfaust.unitywakatime@4dedbea\Editor\Plugin.cs:205)
UnityEditor.SceneManagement.EditorSceneManager:Internal_SceneClosing(Scene, Boolean)

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[])
WakaTime.Plugin:SendHeartbeat(Boolean) (at Library\PackageCache\com.vladfaust.unitywakatime@4dedbea\Editor\Plugin.cs:145)
WakaTime.Plugin:Initialize() (at Library\PackageCache\com.vladfaust.unitywakatime@4dedbea\Editor\Plugin.cs:62)
WakaTime.Plugin:OnScriptReload() (at Library\PackageCache\com.vladfaust.unitywakatime@4dedbea\Editor\Plugin.cs:181)

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[])
WakaTime.Plugin:SendHeartbeat(Boolean) (at Library\PackageCache\com.vladfaust.unitywakatime@4dedbea\Editor\Plugin.cs:145)
WakaTime.Plugin:OnPlaymodeStateChanged(PlayModeStateChange) (at Library\PackageCache\com.vladfaust.unitywakatime@4dedbea\Editor\Plugin.cs:185)
UnityEditor.EditorApplication:Internal_PlayModeStateChanged(PlayModeStateChange)
UnityEditor.EditorApplication:set_isPlaying(Boolean)
Unity.Entities.Editor.LiveLinkToolbar:TogglePlaying() (at Library\PackageCache\com.unity.entities@0.17.0-preview.41\Unity.Entities.Editor\LiveLink\LiveLinkToolbar.cs:94)
Unity.Entities.Editor.LiveLinkToolbar:DrawPlaybar(CommandExecuteContext) (at Library\PackageCache\com.unity.entities@0.17.0-preview.41\Unity.Entities.Editor\LiveLink\LiveLinkToolbar.cs:60)
UnityEditor.CommandService:ExecuteCommand(String, CommandHint, Object[])
UnityEditor.CommandService:Execute(String, CommandHint, Object[])
UnityEditor.ModeService:Execute(String, CommandHint, Object[])
UnityEditor.ModeService:Execute(String, Object[])
UnityEditor.Toolbars.PlayModeButtons:OverrideGUIHandler()
UnityEngine.UIElements.IMGUIContainer:DoOnGUI(Event, Matrix4x4, Rect, Boolean, Rect, Action, Boolean)
UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent(Event, Matrix4x4, Rect, Action, Boolean)
UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent(Event, Action, Boolean)
UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent(Event, Boolean)
UnityEngine.UIElements.IMGUIContainer:SendEventToIMGUIRaw(EventBase, Boolean, Boolean)
UnityEngine.UIElements.IMGUIContainer:SendEventToIMGUI(EventBase, Boolean, Boolean)
UnityEngine.UIElements.IMGUIContainer:HandleEvent(EventBase)
UnityEngine.UIElements.CallbackEventHandler:HandleEventAtTargetPhase(EventBase)
UnityEngine.UIElements.MouseCaptureDispatchingStrategy:DispatchEvent(EventBase, IPanel)
UnityEngine.UIElements.EventDispatcher:ApplyDispatchingStrategies(EventBase, IPanel, Boolean)
UnityEngine.UIElements.EventDispatcher:ProcessEvent(EventBase, IPanel)
UnityEngine.UIElements.EventDispatcher:ProcessEventQueue()
UnityEngine.UIElements.EventDispatcher:OpenGate()
UnityEngine.UIElements.EventDispatcherGate:Dispose()
UnityEngine.UIElements.EventDispatcher:ProcessEvent(EventBase, IPanel)
UnityEngine.UIElements.EventDispatcher:Dispatch(EventBase, IPanel, DispatchMode)
UnityEngine.UIElements.BaseVisualElementPanel:SendEvent(EventBase, DispatchMode)
UnityEngine.UIElements.UIElementsUtility:DoDispatch(BaseVisualElementPanel)
UnityEngine.UIElements.UIElementsUtility:UnityEngine.UIElements.IUIElementsUtility.ProcessEvent(Int32, IntPtr, Boolean&)
UnityEngine.UIElements.UIEventRegistration:ProcessEvent(Int32, IntPtr)
UnityEngine.UIElements.<>c:<.cctor>b__1_2(Int32, IntPtr)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

@HyperGamesDev
Copy link

@HyperGamesDev HyperGamesDev commented Jun 13, 2021

Same here, its leaking memory

@vladfaust vladfaust mentioned this issue Jul 21, 2021
@vladfaust vladfaust added the bug label Jul 21, 2021
@vladfaust
Copy link
Owner

@vladfaust vladfaust commented Jul 21, 2021

I can guess that UploadHandlerRaw shall be disposed properly @

request.uploadHandler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(heartbeatJSON));

@JayPeet
Copy link

@JayPeet JayPeet commented Nov 19, 2021

I think the UnityWebRequest.Post needs to be wrapped in a using statement so that it disposes correctly have Dispose called manually in the completed callback.

I am pretty sure the native collection leak is something which only happens on more recent unity versions, as it is not a problem on pre 2021 versions from what I saw

I can go make a PR with fixes in if needed :)

@JayPeet
Copy link

@JayPeet JayPeet commented Nov 19, 2021

PR is here: #31

@BrianLDev
Copy link

@BrianLDev BrianLDev commented Feb 6, 2022

This bug is still happening and causing constant error messages in Unity. Can someone approve the PR that JayPeet created to fix this?

@vladfaust
Copy link
Owner

@vladfaust vladfaust commented Feb 6, 2022

@BrianLDev

Actually, this sometimes still has the issue.

@BrianLDev
Copy link

@BrianLDev BrianLDev commented Feb 7, 2022

Ah that's a shame. The error messages were getting annoying and I was hoping this would fix it.

@JayPeet
Copy link

@JayPeet JayPeet commented Feb 7, 2022

Yeah, I need to investigate it properly still. Just been too busy :(

@vladfaust
Copy link
Owner

@vladfaust vladfaust commented Feb 9, 2022

I'm not a Unity developer anymore. At least for now. Would be happy if someone takes over this repository. @Hermesiss?

@Hermesiss
Copy link
Collaborator

@Hermesiss Hermesiss commented Feb 10, 2022

Yes, I'm still an active Unity developer. @vladfaust can you transfer this repo to me?

@vladfaust
Copy link
Owner

@vladfaust vladfaust commented Feb 10, 2022

@Hermesiss let's begin with fixing this issue (you're a collaborator) 😃

@Hermesiss
Copy link
Collaborator

@Hermesiss Hermesiss commented Feb 14, 2022

@JayPeet @NachtgeistW @HyperGamesDev Can you provide an example project? I can't reproduce this error

@HyperGamesDev
Copy link

@HyperGamesDev HyperGamesDev commented Feb 14, 2022

my repository SSS222 had WakaTime before, sorry for the inconvenience but you'd have to add it once again now as I removed it(also the Jobs addon). Not sure when it appeared though so it may be difficult to reproduce

@HermesZum
Copy link

@HermesZum HermesZum commented Feb 27, 2022

It's about Unity Engine

public UnityWebRequestAsyncOperation SendWebRequest()
in class UnityWebRequest
Begin communicating with the remote server.
External documentation for UnityWebRequest.SendWebRequest

If this operation can be replaced for other the problem will be solved.

for example, if you use the obsolete: Method 'UnityEngine.Networking.UnityWebRequest.Send' is obsolete: Use SendWebRequest. It returns a UnityWebRequestAsyncOperation which contains a reference to the WebRequest object.

The leak disapear.

@Plutonian0
Copy link

@Plutonian0 Plutonian0 commented May 18, 2022

Hello! Curious if this has been investigated yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug
Projects
None yet
Development

No branches or pull requests

8 participants