tag:blogger.com,1999:blog-7395797351911594965.post2444952658234307684..comments2024-03-24T23:19:53.674-07:00Comments on Richard Geldreich's Blog: Lessons learned while fixing memory leaks in our first Unity titleRich Geldreichhttp://www.blogger.com/profile/14358203173986928600noreply@blogger.comBlogger15125tag:blogger.com,1999:blog-7395797351911594965.post-2910927409994582502017-02-14T23:33:37.851-08:002017-02-14T23:33:37.851-08:00I'm using Unity3D 5.5.0, iOS 9.3.2, XCode 8.1....I'm using Unity3D 5.5.0, iOS 9.3.2, XCode 8.1. However this weird behaviour reoccurs across different versions of the aforementioned software. And it seems to be not the overhead of the XCode profiler since I'm not actually profiling but rather just running the application from XCode. There is a Debug navigator which (I hope) doesn't introduce any runtime overhead or does it?Anonymoushttps://www.blogger.com/profile/03862103116820975301noreply@blogger.comtag:blogger.com,1999:blog-7395797351911594965.post-90096479292974083182017-02-13T12:56:01.172-08:002017-02-13T12:56:01.172-08:00We've definitely seen different numbers from U...We've definitely seen different numbers from Unity's profiler, XCode, and Instruments (and with the numbers we get using OS status APIs). The difference you may be seeing could be overhead that XCode inflicts with profiling, or something else that isn't immediately obvious from the normal API calls that Unity uses internally.<br /><br />What version of Unity3D, Xcode, and iOS are you running?kornman00https://www.blogger.com/profile/01130515348227313715noreply@blogger.comtag:blogger.com,1999:blog-7395797351911594965.post-54088316449290760272017-02-08T12:15:48.901-08:002017-02-08T12:15:48.901-08:00Great post, thanks! We are also struggling with Un...Great post, thanks! We are also struggling with Unity3d application memory consumption. However the biggest issue so far is different numbers shown by Unity3d's profiler and XCode. Internal profiler doesn't show extra 60-80Mb reported by XCode :( Have you ever observed similar behavior?pachangahttps://www.blogger.com/profile/12434709367397997534noreply@blogger.comtag:blogger.com,1999:blog-7395797351911594965.post-89659294622364487752016-08-25T09:56:28.233-07:002016-08-25T09:56:28.233-07:00We switched our content downloader from using WWW ...We switched our content downloader from using WWW to using .NET's System.Net.WebClient class. Effectively working around Unity's problem of creating a heap allocation for the full size of whatever content. If you do the same, you'll need to use link.xml to ensure it isn't stripped from your builds.kornman00https://www.blogger.com/profile/01130515348227313715noreply@blogger.comtag:blogger.com,1999:blog-7395797351911594965.post-91997826306775096072016-07-26T15:12:41.331-07:002016-07-26T15:12:41.331-07:00"- Be very careful about using Unity's WW..."- Be very careful about using Unity's WWW class to download large archives or bundles, because this class may store the downloaded data in the mono heap. This is actually a serious problem for us, because we download compressed Unity asset bundles during the user's first game session and this class was causing our app's mono memory footprint to be increased by 30-40MB. This seriously reduced our app's memory headroom during the user's first session (which in a free to play game is pretty critical to get right)."<br /><br />So what if my app has a feature that needs fetch images from URL based on each search request? Any suggestions? I am so crazy about it since it always crashes after a few search requests.Anonymoushttps://www.blogger.com/profile/12346654247573045324noreply@blogger.comtag:blogger.com,1999:blog-7395797351911594965.post-27285910916307883502016-02-05T09:24:15.575-08:002016-02-05T09:24:15.575-08:00This is honestly why I stick with C++. Proper use ...This is honestly why I stick with C++. Proper use of the constructor/destructor pattern guarantees no leaks in memory ever happen and instant destruction keeps my memory usage down.<br /><br />Languages like C# and Java are nice when you're making a simple application that doesn't have to care how much memory it's using, but they are never the one to use when you need to keep resource usage down.cdaragornhttps://www.blogger.com/profile/04064042861366003442noreply@blogger.comtag:blogger.com,1999:blog-7395797351911594965.post-25824229713734417012016-01-16T16:22:49.960-08:002016-01-16T16:22:49.960-08:00If there's enough interest, I could detail the...If there's enough interest, I could detail the transaction log used in our instrumented DLL (https://github.com/KornnerStudios/mono/tree/unity-4.6) on my blog http://kornnerstudios.blogspot.com/.<br /><br />Especially since there's no obvious timeline when there will be a standalone that supports IL2CPP. At which point you (and I) could use Unity's memory tool https://bitbucket.org/Unity-Technologies/memoryprofiler (although it's still pretty rough)kornman00https://www.blogger.com/profile/01130515348227313715noreply@blogger.comtag:blogger.com,1999:blog-7395797351911594965.post-4456499164104417512016-01-07T10:07:49.258-08:002016-01-07T10:07:49.258-08:00I think you could, but you would need to write a t...I think you could, but you would need to write a tool to analyze the transaction log data.Rich Geldreichhttps://www.blogger.com/profile/14358203173986928600noreply@blogger.comtag:blogger.com,1999:blog-7395797351911594965.post-49553215485094454332016-01-07T09:17:03.651-08:002016-01-07T09:17:03.651-08:00I guess it's not possible to use your instrume...I guess it's not possible to use your instrumented DLL out of the box for standalone windows application, am I right?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7395797351911594965.post-41795613326672013862015-10-09T07:32:06.730-07:002015-10-09T07:32:06.730-07:00Hey, there is a new memory profiler for Unity 5.3 ...Hey, there is a new memory profiler for Unity 5.3 beta. It tracks native and managed objects. It is for Il2cpp only. The gui part isn't very useful in its current beta stage but it is open source. You can easily grab the underlying data and process them any way you like. It really helped me to track down a memory "leak". Maybe it will help somebody here. https://bitbucket.org/Unity-Technologies/memoryprofilerMichal Skalskyhttps://www.blogger.com/profile/11352928461461791353noreply@blogger.comtag:blogger.com,1999:blog-7395797351911594965.post-82245766844890230362015-06-25T23:56:25.866-07:002015-06-25T23:56:25.866-07:00Thanks 411. We've split up our downloads into ...Thanks 411. We've split up our downloads into multiple (smaller) chunks. Doesn't solve the problem but it minimizes the spike's size.Rich Geldreichhttps://www.blogger.com/profile/14358203173986928600noreply@blogger.comtag:blogger.com,1999:blog-7395797351911594965.post-21127711232591536502015-06-25T23:56:18.141-07:002015-06-25T23:56:18.141-07:00Thanks 411. We've split up our downloads into ...Thanks 411. We've split up our downloads into multiple (smaller) chunks. Doesn't solve the problem but it minimizes the spike's size.Rich Geldreichhttps://www.blogger.com/profile/14358203173986928600noreply@blogger.comtag:blogger.com,1999:blog-7395797351911594965.post-20090655092749084422015-06-25T22:08:34.201-07:002015-06-25T22:08:34.201-07:00Hey, just found your blog, love it! What did you g...Hey, just found your blog, love it! What did you guys do about the initial mem spike from bundle/asset downloads?411https://www.blogger.com/profile/01564709354837431927noreply@blogger.comtag:blogger.com,1999:blog-7395797351911594965.post-48939597039463476972015-05-22T19:12:09.699-07:002015-05-22T19:12:09.699-07:00When we started we were doing all of our heap anal...When we started we were doing all of our heap analysis on iOS. This was a pain for various mostly logistical reasons, because copying huge transaction logs from our phones over to our development PC's was slowing us down. So we switched to using a Unity Windows standalone build of our game to speed things up. (We actually only added support for Windows standalone builds specifically to speed up memory analysis.)<br /><br />Another developer here (Sean Cooper) worked on building and customizing the open source version of Mono that ships with Unity. I think we started doing this after we switched to Windows for analysis purposes, so I'm not sure if you can do this on iOS offhand (I'll ask him).<br />Rich Geldreichhttps://www.blogger.com/profile/14358203173986928600noreply@blogger.comtag:blogger.com,1999:blog-7395797351911594965.post-86203726979752538212015-05-22T00:48:36.381-07:002015-05-22T00:48:36.381-07:00Great info! It's interesting that you went as ...Great info! It's interesting that you went as far as building your own instrumented mono. Can you drop that in to Unity and use it on an iOS device? I find the Unity profiler to generally be pretty good but sometimes it's not all that obvious where the memory is going or why it's all being used up. Your greediness comment kind of helps explain that a bit!Samhttps://www.blogger.com/profile/01843393036648718286noreply@blogger.com