Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by chenyiguo · Sep 06, 2019 at 09:46 AM · memory-leak

Unity2019.2.1f1 Heap Memory leak

At ios platform,when alloc a huge buffer like: var bytes = new bytes[100 1024 1024]; bytes = null; GC.Collect(); Runtime momery increase 100M,and couldn't decrease

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by MartinTilo · Sep 06, 2019 at 09:35 PM

Please check Memory usage with the Memory Profiler instead of a system monitor. Those monitors only display what they can see from the outside. However, Unity does not reduce Memory pool sizes, including that of the managed heap, even though it does reduce the usage of these pools (the Memory Profiler would show usage and reserved pool sizes).

Another way to test this would be to validate that you can allocate another array of the same size without increasing the apps memory footprint (if no further allocations happened). Which would also mean it's not a leak.

That said, if you do find a memory leak, please report it using the menu entry "Help -> Report A Bug" instead to make sure it doesn't get lost and can be fixed.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image chenyiguo · Sep 10, 2019 at 07:09 AM 0
Share

Thanks for reply. (1).At the IOS platform with il2cpp, can't managed heap reserved sizes be released and back to os? If alloc a large memory,even though the useage memory has gc correctly,do the reseved memory pool still remain the large sizes? (2).In a function, repeatly alloc buffers 10$$anonymous$$ 20$$anonymous$$ ... 90$$anonymous$$ 100$$anonymous$$ incrementally like: var bytes1 = new bytes[10 1024 1024]; var bytes2 = new bytes[20 1024 1024]; ... var bytes10 = new bytes[100 1024 1024]; The total memory size increase 100$$anonymous$$. But on the contrary,alloc 100$$anonymous$$ 90$$anonymous$$ ...20$$anonymous$$ 10$$anonymous$$, memory increase190$$anonymous$$. Does the memory pool work correctly? (3).If i create a $$anonymous$$emoryStream,and keep writing about 100$$anonymous$$ data at a time.When the size of $$anonymous$$emoryStream grown to 200$$anonymous$$,the reserved memory increase to 1.4G. So app runs at Iphone6s crash because of memory. This happend in Unity2019.2.1, and will not happen in Unity2017.4.1. Is this a bug for Unity?

avatar image MartinTilo chenyiguo · Sep 30, 2019 at 11:43 AM 1
Share

(1) The managed heap is a non-compacting, non-moving garbage collected heap. So fragmentation could keep pages from being released. Also, requesting new memory from the OS takes time. So Unity does not release managed memory pools ever. Native ones can get released eventually, might differ from platform to platform though.


(2) you'd want to make sure that the memory of the previous allocation has been fully collected with no new allocations in between that could have fragmented the memory so that there is not enough space to fit the 100$$anonymous$$ alloc into the 90$$anonymous$$ alloc whole. also see this API since requesting a GC.Collect does not actually enforce that GC is run right there and then but might just schedule it.


(3) Sounds more like a difference between C# versions/Scripting Back-end versions but I can't answer this definitively here (maybe try the forums, or $$anonymous$$ono Repos). $$anonymous$$emoryStream might have some caching memory behind it that could cause this and then that could be a change introduced by $$anonymous$$icrosoft's implementation to which $$anonymous$$ono has to keep binary compatibility.

avatar image
0

Answer by BenR · Apr 03, 2020 at 08:09 PM

I believe I have run into the same issue on iOS. In my case I am serializing a large amount of data via Json.NET. If I try to serialize through a memorystream then memory usage goes over a gb and is never released. If I run it twice I get an app crash. The only way I can get it to work is to serialize into a StreamWriter writing to a file.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

111 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Assetbundle memory leaks 0 Answers

VRam keeps climbing until Unity editor crashes. 1 Answer

Kinect SensorData Memory Leak 1 Answer

Performance going down over time 2 Answers

Memory leak but only in the executable 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges