{"id":95867,"date":"2020-04-04T22:05:24","date_gmt":"2020-04-04T14:05:24","guid":{"rendered":"http:\/\/4563.org\/?p=95867"},"modified":"2020-04-04T22:05:24","modified_gmt":"2020-04-04T14:05:24","slug":"%e5%86%99%e7%bb%99-unity-%e5%bc%80%e5%8f%91%e8%80%85%e7%9a%84-ios-%e5%86%85%e5%ad%98%e8%b0%83%e8%af%95%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=95867","title":{"rendered":"\u5199\u7ed9 Unity \u5f00\u53d1\u8005\u7684 iOS \u5185\u5b58\u8c03\u8bd5\u6307\u5357"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5199\u7ed9 Unity \u5f00\u53d1\u8005\u7684 iOS \u5185\u5b58\u8c03\u8bd5\u6307\u5357               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : unn <\/span>  <span><i><\/i> 49<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u804a\u804a Unity \u7a0b\u5e8f\u5458\u53ef\u80fd\u4f1a\u9047\u5230\u7684 iOS \u5185\u5b58\u95ee\u9898\u3002iOS \u7684\u5185\u5b58\u7ba1\u7406\u673a\u5236\u662f\u4ec0\u4e48\uff1f\u600e\u4e48\u67e5\u770b\u67d0\u4e00\u5757\u5f88\u5927\u7684\u5185\u5b58\u5206\u914d\u7684\u5806\u6808\u8c03\u7528\uff1f\u6258\u7ba1\u5185\u5b58\u662f\u5982\u4f55\u5206\u914d\u7684\uff1f\u6233\u3002 0x00 \u524d\u8a00<\/p>\n<p>\u5de5\u4f5c\u7684\u8fc7\u7a0b\u4e2d\uff0c\u5e38\u5e38\u4f1a\u53d1\u73b0\u6709\u5c0f\u4f19\u4f34\u5bf9 Unity \u7684 Profiler \u63d0\u4f9b\u7684\u5185\u5b58\u6570\u636e\u4e0e\u67d0\u4e9b\u539f\u751f\u5e73\u53f0 Profiler \u5de5\u5177\uff0c\u4f8b\u5982 iOS \u7cfb\u7edf\u548c Xcode\uff0c\u6240\u63d0\u4f9b\u7684\u5185\u5b58\u6570\u636e\u6709\u5dee\u5f02\u800c\u611f\u5230\u597d\u5947\u3002\u800c\u4e14\u5927\u5bb6\u5bf9\u5982\u4f55\u89e3\u8bfb\u539f\u751f\u5e73\u53f0\u5de5\u5177\u7684\u6570\u636e\u66f4\u52a0\u611f\u5174\u8da3\uff0c\u540c\u6837\u4f8b\u5982 iOS \u7cfb\u7edf\u548c Xcode\u3002\u6700\u8fd1\u6b63\u597d\u770b\u4e86\u4e00\u4e2a\u6765\u81ea Unite Copenhagen \u9898\u4e3a Developing and optimizing a procedural game | The Elder Scrolls Blades &#8211; Unite Copenhagen \u7684\u6f14\u8bb2\uff0c\u5176\u4e2d\u5c31\u6d89\u53ca\u5230\u4e86\u4e00\u4e9b\u5173\u4e8e iOS \u5185\u5b58\u7684\u8bdd\u9898(\u867d\u7136\u5e76\u4e0d\u662f\u5f88\u8be6\u7ec6)\u3002\u6b63\u597d\u4e5f\u7ed3\u5408\u5de5\u4f5c\u4e2d\u7684\u4e00\u4e9b\u7ecf\u9a8c\uff0c\u5199\u4e00\u7bc7\u6587\u7ae0\u6765\u8ba8\u8bba\u4e00\u4e0b\u4e00\u4e2a Unity \u5f00\u53d1\u8005\u5982\u4f55\u5904\u7406\u548c iOS \u5185\u5b58\u6709\u5173\u7684\u95ee\u9898\u3002\u4e3b\u8981\u5185\u5bb9\u5305\u62ec\u89e3\u6790 iOS \u7cfb\u7edf\u7684\u5185\u5b58\u7ba1\u7406\uff0c\u4f7f\u7528 Instrument \u67e5\u770b Unity \u6e38\u620f\u7684\u5185\u5b58\u72b6\u51b5\uff0c\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u6df1\u5165\u6316\u6398 Unity \u6e38\u620f\u7684\u5185\u5b58\u95ee\u9898\u4ee5\u53ca\u6587\u672b\u5c0f\u5f69\u86cb\u3002 0x01 iOS \u7684\u5185\u5b58\u7ba1\u7406 &#8211; Unity Profiler \u7edf\u8ba1\u9519\u4e86\u5417\uff1f<\/p>\n<p>\u9996\u5148\uff0c\u6211\u60f3\u5f3a\u8c03\u7684\u4e00\u70b9\u662f\uff0cProfiler \u5de5\u5177\u6240\u63d0\u4f9b\u7684\u5185\u5b58\u6570\u636e\u53ea\u662f\u4e00\u4e2a\uff08\u7ec4\uff09\u6570\u5b57\uff0c\u800c\u4e14\u4e0d\u540c\u7684\u5de5\u5177\u5b58\u5728\u6709\u4e0d\u540c\u7edf\u8ba1\u5185\u5b58\u7684\u7b56\u7565\u3002\u56e0\u6b64\uff0c\u4e00\u4e2a\u91cd\u8981\u7684\u95ee\u9898\u662f\u6211\u4eec\u770b\u5230\u7684\u6570\u636e\u7a76\u7adf\u662f\u5982\u4f55\u83b7\u53d6\u7684\uff1f \u800c\u6839\u636e\u6240\u4f7f\u7528\u7684\u5de5\u5177\u4e0d\u540c\uff0c\u8be5\u5de5\u5177\u7528\u4e8e\u67e5\u627e\u6570\u636e\u7684\u7b56\u7565\u4ee5\u53ca\u5f00\u53d1\u4eba\u5458\u5b9e\u9645\u8981\u67e5\u627e\u7684\u5185\u5bb9\uff0c\u6700\u540e\u7684\u7ed3\u679c\u4e5f\u6709\u53ef\u80fd\u662f\u4e0d\u4e00\u6837\u7684\u3002\u56e0\u6b64\uff0c\u5982\u679c\u8981\u5bfb\u627e\u4e00\u4e2a\u6570\u5b57\u6765\u6c47\u603b\u67d0\u4e2a\u5e94\u7528\u6216\u8005\u6e38\u620f\u7684\u6240\u6709\u5185\u5b58\u4fe1\u606f\uff0c\u90a3\u4e48\u53ef\u80fd\u662f\u628a\u95ee\u9898\u60f3\u7b80\u5355\u4e86\uff0c\u6216\u8005\u8bf4\u5ffd\u7565\u4e86\u7cfb\u7edf\u7684\u590d\u6742\u6027\u3002\u4f8b\u5982\uff0c\u4e0d\u540c\u7248\u672c\u7684 iOS \u5176\u5bf9\u5185\u5b58\u5f00\u9500\u7684\u7edf\u8ba1\u90fd\u662f\u6709\u533a\u522b\u7684\u2014\u2014\u5728 iOS12 \u4e0a\u8fd0\u884c\u7684 metal app \u7684\u5185\u5b58\u5728 Xcode memory gauge \u7684\u7edf\u8ba1\u662f\u9ad8\u4e8e iOS11 \u7684\uff0c\u8fd9\u540c\u6837\u662f\u7531\u4e8e\u82f9\u679c\u6539\u53d8\u4e86\u5bf9\u5185\u5b58\u7684\u7edf\u8ba1\u7b56\u7565\uff0c\u5f88\u591a\u4e4b\u524d\u6ca1\u6709\u88ab\u7edf\u8ba1\u7684\u5185\u5b58\u5982\u4eca\u4e5f\u88ab\u8ba1\u7b97\u5230\u4e86\u5185\u5b58\u5f00\u9500\u4e2d\u3002\u800c\u540c\u6837\u90fd\u662f iOS\uff0cXcode memory gauge \u7684\u7edf\u8ba1\u548c Instrument \u4e2d\u7684\u7edf\u8ba1\u4e5f\u6709\u53ef\u80fd\u4e0d\u5b8c\u5168\u4e00\u81f4\uff0c\u800c\u65e9\u671f Instrument \u7684 Allocation \u5219\u4e3b\u8981\u7528\u6765\u7edf\u8ba1 heap \u5185\u5b58\uff0c\u53ea\u80fd\u8bf4\u6839\u636e\u5404\u81ea\u5de5\u5177\u7684\u7edf\u8ba1\u89c4\u5219\uff0c\u5927\u5bb6\u90fd\u662f\u6b63\u786e\u7684\u3002\u56e0\u6b64\uff0c\u628a\u65f6\u95f4\u6d6a\u8d39\u5728\u5bf9\u6bd4\u4e0d\u540c\u5de5\u5177\u7684\u6570\u636e\u4e0a\u8fd8\u4e0d\u5982\u4ee5\u4e00\u4e2a\u5de5\u5177\u4f5c\u4e3a\u6807\u5c3a\u6765\u8861\u91cf\u5185\u5b58\u5f00\u9500\u6216\u8005\u662f\u5224\u65ad\u5185\u5b58\u7684\u4f18\u5316\u662f\u5426\u6709\u6548\u3002 The accounting for purgeable, nonvolatile memory changed beginning in iOS 12 and tvOS 12. In iOS 11 and tvOS 11, allocations with this memory storage mode\u2014commonly used by Metal apps to store buffers, textures, and state objects\u2014weren\u2019t counted toward an app\u2019s memory limit and weren\u2019t presented in tools like Xcode memory gauge. \u6240\u4ee5\uff0c\u4e86\u89e3\u64cd\u4f5c\u7cfb\u7edf\u662f\u5982\u4f55\u7ba1\u7406\u5185\u5b58\u5c31\u53d8\u5f97\u5341\u5206\u91cd\u8981\uff0c\u5bf9\u4e8e\u5982\u4f55\u89e3\u8bfb Profiler \u5de5\u5177\u63d0\u4f9b\u7684\u6570\u636e\u4e5f\u5f88\u6709\u5e2e\u52a9\u3002\u63a5\u4e0b\u6765\u6211\u4eec\u5148\u6765\u8ba8\u8bba\u4e00\u4e0b iOS \u7cfb\u7edf\u5bf9\u5185\u5b58\u7684\u7ba1\u7406\u673a\u5236\uff0c\u4e4b\u540e\u518d\u6765\u5206\u522b\u770b\u770b Xcode \u6293\u53d6\u7684\u5185\u5b58\u6570\u636e\u548c Unity \u6293\u53d6\u7684\u5185\u5b58\u6570\u636e\u3002 \u9996\u5148\uff0c\u6bcf\u4e00\u4e2a\u8fdb\u7a0b\u90fd\u4f1a\u6709\u4e00\u4e2a\u5730\u5740\u7a7a\u95f4\u3002\u5176\u8303\u56f4\u7531\u6307\u9488 size \u652f\u6301\uff0c\u6bd4\u5982 32bit \u6216 64bit\u3002\u5e76\u4e14\u5730\u5740\u7a7a\u95f4\u9996\u5148\u4f1a\u5206\u4e3a\u591a\u4e2a\u533a\u57df\uff08 regions \uff09\uff0c\u7136\u540e\u5c06\u8fd9\u4e9b\u533a\u57df\u7ec6\u5206\u4e3a 4KB \uff08\u65e9\u671f\u7248\u672c\uff09\u6216 16KB \uff08 A7 \u4e4b\u540e\uff09\u4e3a\u5355\u4f4d\u7684 page\uff0c\u8fd9\u4e9b page \u7ee7\u627f\u4e86\u8be5 region \u7684\u5404\u79cd\u5c5e\u6027\uff0c\u4f8b\u5982\u662f\u5426\u662f\u53ea\u8bfb\u3001\u53ef\u8bfb\u5199\u7b49\u7b49\u3002\u5f53\u7136\uff0c\u6709\u4e9b page \u53ef\u80fd\u5b58\u653e\u7684\u6570\u636e\u6bd4\u8fd9\u4e2a page \u7684\u5c3a\u5bf8\u8981\u5c0f\uff0c\u6709\u7684\u6570\u636e\u53ef\u80fd\u9700\u8981\u597d\u51e0 page \u624d\u80fd\u5b58\u653e\uff0c\u4f46\u662f\u7cfb\u7edf\u7684\u5185\u5b58\u5355\u4f4d\u662f 16kb \u7684 page\uff0c\u6240\u4ee5\u7cfb\u7edf\u7edf\u8ba1\u7684\u5185\u5b58\u5f00\u9500\u7ea6\u7b49\u4e8e page \u7684\u6570\u91cf x page \u7684\u5927\u5c0f\u3002 \u5f53\u7136\uff0c\u7cfb\u7edf\u8fd8\u6709\u771f\u5b9e\u7684\u7269\u7406\u5185\u5b58\u3002 Virtual memory vs Resident memory<\/p>\n<p>ref: WWDC 2013 \u901a\u8fc7\u865a\u62df\u5185\u5b58\u4f7f\u6211\u4eec\u80fd\u591f\u5efa\u7acb\u4ece\u8be5\u5730\u5740\u7a7a\u95f4\u5230\u771f\u5b9e\u7269\u7406\u5185\u5b58\u7684\u6620\u5c04\uff0c\u8fd9\u70b9\u6211\u60f3\u8fd9\u4e9b\u5927\u5bb6\u5e94\u8be5\u90fd\u77e5\u9053\u3002\u800c\u6620\u5c04\u5176\u5b9e\u662f\u4e00\u4e2a\u5f88\u6709\u8da3\u7684\u4e8b\u60c5\u3002\u56e0\u4e3a\u4ece\u6bcf\u4e00\u4e2a app \u8fdb\u7a0b\u7684\u89d2\u5ea6\u6765\u770b\uff0c\u5b83\u62e5\u6709\u6240\u6709\u7684\u5185\u5b58\uff0c\u5373\u865a\u62df\u5185\u5b58\uff0c\u4f46\u4e8b\u5b9e\u4e0a\u53ea\u6709\u4e00\u90e8\u5206\u865a\u62df\u5185\u5b58\u88ab\u6620\u5c04\u5230\u4e86\u771f\u5b9e\u7684\u7269\u7406\u5185\u5b58\u4e0a\uff0c\u8fd9\u90e8\u5206\u88ab\u6620\u5c04\u5230\u7269\u7406\u5185\u5b58\u7684\u90e8\u5206\u5c31\u662f\u6240\u8c13\u7684 Resident memory\u3002 \u5c31\u50cf\u4e0a\u9762\u8fd9\u4e2a\u56fe\u4e2d\u63cf\u8ff0\u7684\u4e00\u6837\uff0c\u4e00\u4e2a app \u5206\u914d\u4e86\u5185\u5b58\uff0c\u53ef\u4ee5\u770b\u5230\u5728\u865a\u62df\u5185\u5b58\u4e0a\u5206\u914d\u4e86 4 \u4e2a region\uff0c\u5176\u4e2d\u7b2c 3 \u4e2a region \u5305\u62ec\u4e86 13 \u4e2a page\u3002 \u4f46\u6b64\u65f6\uff0c\u771f\u6b63\u6620\u5c04\u5230\u7269\u7406\u5185\u5b58\u4e0a\u7684\u53ea\u6709 6 \u4e2a page\u3002\u800c\u865a\u62df\u5185\u5b58\u5230\u771f\u5b9e\u7269\u7406\u5185\u5b58\u7684\u6620\u5c04\u53d1\u751f\u5728\u5bf9\u5185\u5b58\u7684\u7b2c\u4e00\u6b21\u4f7f\u7528\u65f6\uff0c\u6bd4\u5982\u4ece\u5185\u5b58\u4e2d\u8bfb\u53d6\u6570\u636e\u6216\u662f\u5411\u5185\u5b58\u4e2d\u5199\u6570\u636e\u3002Resident memory \u540c\u6837\u4e5f\u662f Virtual memory\uff0c\u53ea\u4e0d\u8fc7\u8fd9\u90e8\u5206 Virtual memory \u5df2\u7ecf\u6620\u5c04\u5230\u4e86\u771f\u5b9e\u7684\u7269\u7406\u5185\u5b58\u3002 \u6211\u60f3\u5927\u5bb6\u53ef\u80fd\u90fd\u901a\u8fc7 XCode \u6216\u8005 Instrument \u7684\u7edf\u8ba1\u770b\u5230\u8fc7\u7c7b\u4f3c\u7684\u6570\u636e\uff0c\u4f8b\u5982 Instrument \u7684 VM Tracker \u4e2d\u5c31\u5206\u522b\u5217\u51fa\u4e86 Resident \u548c Virtual Size\u3002 Dirty memory vs Clean memory<\/p>\n<p>page \u6709\u53ef\u80fd\u662f dirty \u7684\u4e5f\u6709\u53ef\u80fd\u662f clean \u7684\u3002\u8981\u5982\u4f55\u533a\u5206 dirty \u548c clean \u5462\uff1f\u7b80\u5355\u7684\u8bf4\uff0cdirty \u7684\u9875\u5c31\u662f\u6211\u4eec\u7684 app \u6216\u8005\u6e38\u620f\u5bf9\u8fd9\u4e2a page \u7684\u5185\u5bb9\u8fdb\u884c\u4e86\u4fee\u6539\u5373\u5206\u914d\u4e86\u5185\u5b58\u540c\u65f6\u4e5f\u4fee\u6539\u4e86\u5185\u5b58\u7684\u5185\u5bb9\uff0c\u5e38\u89c1\u7684\u5c31\u662f malloc \u5728 heap \u4e0a\u5206\u914d\u7684\u5185\u5b58\u3002\u8fd9\u90e8\u5206\u5185\u5b58\u662f\u4e0d\u80fd\u88ab\u56de\u6536\u7684\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u6570\u636e\u663e\u7136\u9700\u8981\u88ab\u4fdd\u5b58\u5728\u5185\u5b58\u4e2d\u4ee5\u4fdd\u8bc1\u7a0b\u5e8f\u6b63\u5e38\u7684\u8fd0\u884c\u3002 \u800c clean \u7684\u9875\u5219\u662f\u6ca1\u6709\u5bf9\u5176\u5185\u5bb9\u8fdb\u884c\u4fee\u6539\uff0c\u53ef\u4ee5\u88ab\u7cfb\u7edf\u6536\u56de\u548c\u91cd\u65b0\u521b\u5efa\u7684\u3002\u4f8b\u5982\u5185\u5b58\u6620\u5c04\u6587\u4ef6\uff08 Memory-mapped file \uff09\uff0c\u5982\u679c\u64cd\u4f5c\u7cfb\u7edf\u9700\u8981\u66f4\u591a\u7684\u5185\u5b58\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u5c06\u5176\u4e22\u5f03\u3002\u56e0\u4e3a\u7cfb\u7edf\u603b\u662f\u53ef\u4ee5\u4ece\u78c1\u76d8\u4e2d\u91cd\u65b0\u52a0\u8f7d\u5b83\uff0c\u521b\u5efa\u5185\u5b58\u7a7a\u95f4\u548c\u78c1\u76d8\u4e0a\u6587\u4ef6\u7684\u6620\u5c04\u5173\u7cfb\u3002clean \u7684\u5185\u5b58\u662f\u53ef\u4ee5\u88ab\u91ca\u653e\u548c\u91cd\u65b0\u521b\u5efa\u7684\u3002\u4f46\u662f\u53ef\u4ee5\u770b\u5230\uff0c\u867d\u7136 Memory-mapped file \u5e76\u6ca1\u6709\u6d88\u8017\u771f\u5b9e\u7684\u7269\u7406\u5185\u5b58\uff0c\u4f46\u662f\u5b83\u6d88\u8017\u4e86\u8fdb\u7a0b\u7684\u865a\u62df\u5185\u5b58\u3002 \u9664\u6b64\u4e4b\u5916\u8fd8\u6709\u53ef\u6267\u884c\u6587\u4ef6\u7684__TEXT \u6bb5\u4ee5\u53ca\u4e00\u4e9b framework \u7684 DATA CONST \u6bb5\uff0c\u4e5f\u4f1a\u5f52\u4e3a clean memory\u3002 \u5728 WWDC2018 \u4e0a\uff0ciOS \u7684\u5f00\u53d1\u4eba\u5458\u4e3e\u4e86\u4e00\u4e2a\u5f88\u5f62\u8c61\u7684\u4f8b\u5b50\u3002\u5373\u5206\u914d 20,000 \u4e2a integers \u7ec4\u6210\u7684 array\uff0c\u6b64\u65f6\u4f1a\u6709 page \u88ab\u521b\u5efa\uff0c\u5982\u679c\u53ea\u5bf9\u7b2c\u4e00\u4e2a\u5143\u7d20\u548c\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u8d4b\u503c\uff0c\u5219\u7b2c\u4e00\u4e2a page \u548c\u6700\u540e\u4e00\u4e2a page\u2014\u2014\u5373\u9996\u5c3e\u5143\u7d20\u6240\u5728\u7684 page\u2014\u2014\u4f1a\u53d8\u6210 dirty\uff0c\u4f46\u662f\u9996\u5c3e\u4e4b\u95f4\u7684 page \u4ecd\u7136\u662f clean\uff0c\u5373\u53ea\u5206\u914d\u4e86\u5185\u5b58\u800c\u6ca1\u6709\u4fee\u6539\u6216\u5199\u6570\u636e\u3002<\/p>\n<p>ref: WWDC 2018 Compressed memory<\/p>\n<p>\u5f53\u5185\u5b58\u5403\u7d27\u65f6\uff0c\u4f1a\u56de\u6536 clean page\u3002\u800c dirty page \u662f\u4e0d\u80fd\u88ab\u56de\u6536\u7684\uff0c\u90a3\u4e48\u5982\u679c dirty memory \u8fc7\u591a\u4f1a\u5982\u4f55\u5462\uff1f\u5728 iOS7 \u4e4b\u524d\uff0c\u5982\u679c\u8fdb\u7a0b\u7684 dirty memory \u8fc7\u9ad8\u5219\u7cfb\u7edf\u4f1a\u76f4\u63a5\u7ec8\u6b62\u8fdb\u7a0b\u3002iOS7 \u4e4b\u540e\uff0c\u5f15\u5165\u4e86 Compressed Memory \u7684\u673a\u5236\u3002\u7531\u4e8e iOS \u6ca1\u6709\u4f20\u7edf\u610f\u4e49\u4e0a\u7684 disk swap \u673a\u5236\uff08 mac OS \u6709\uff09\uff0c\u56e0\u6b64\u6211\u4eec\u5728\u82f9\u679c\u7684 Profiler \u5de5\u5177\u4e2d\u770b\u5230\u7684 Swapped Size \u6307\u7684\u5176\u5b9e\u5c31\u662f Compressed Memory\u3002 iOS7 \u4e4b\u540e\uff0c\u64cd\u4f5c\u7cfb\u7edf\u53ef\u4ee5\u901a\u8fc7\u5185\u5b58\u538b\u7f29\u5668\u6765\u5bf9 dirty \u5185\u5b58\u8fdb\u884c\u538b\u7f29\u3002\u9996\u5148\uff0c\u9488\u5bf9\u90a3\u4e9b\u6709\u4e00\u6bb5\u65f6\u95f4\u6ca1\u6709\u88ab\u8bbf\u95ee\u7684 dirty pages \uff08\u591a\u4e2a page \uff09\uff0c\u5185\u5b58\u538b\u7f29\u5668\u4f1a\u5bf9\u5176\u8fdb\u884c\u538b\u7f29\u3002\u4f46\u662f\uff0c\u5728\u8fd9\u5757\u5185\u5b58\u518d\u6b21\u88ab\u8bbf\u95ee\u65f6\uff0c\u5185\u5b58\u538b\u7f29\u5668\u4f1a\u5bf9\u5b83\u89e3\u538b\u4ee5\u6b63\u786e\u7684\u8bbf\u95ee\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u67d0\u4e2a Dictionary \u4f7f\u7528\u4e86 3 \u4e2a page \u7684\u5185\u5b58\uff0c\u5982\u679c\u4e00\u6bb5\u65f6\u95f4\u6ca1\u6709\u88ab\u8bbf\u95ee\u540c\u65f6\u5185\u5b58\u5403\u7d27\uff0c\u5219\u7cfb\u7edf\u4f1a\u5c1d\u8bd5\u5bf9\u5b83\u8fdb\u884c\u538b\u7f29\u4ece 3 \u4e2a page \u538b\u7f29\u4e3a 1 \u4e2a page \u4ece\u800c\u91ca\u653e\u51fa 2 \u4e2a page \u7684\u5185\u5b58\u3002\u4f46\u662f\u5982\u679c\u4e4b\u540e\u9700\u8981\u5bf9\u5b83\u8fdb\u884c\u8bbf\u95ee\uff0c\u5219\u5b83\u5360\u7528\u7684 page \u53c8\u4f1a\u53d8\u4e3a 3 \u4e2a\u3002 Unity Profiler \u9519\u4e86\u5417\uff1f<\/p>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u4ece\u64cd\u4f5c\u7cfb\u7edf\u5185\u5b58\u7ba1\u7406\u7684\u89d2\u5ea6\u6765\u770b\uff0c\u4e00\u4e2a\u8fdb\u7a0b\u7684\u5185\u5b58\u5176\u5b9e\u662f\u5341\u5206\u590d\u6742\u7684\u3002\u800c Unity \u8bb0\u5f55\u7684\u5185\u5b58\u6570\u636e\uff0c\u4ee5\u201cReserved Total &#8211; Unity\u201d\u4e3a\u4f8b\uff0c\u5219\u4e3b\u8981\u6765\u81ea\u5f15\u64ce\u5185 MemoryManager \u7684\u8bb0\u5f55\u3002MemoryManager \u4f1a\u6839\u636e\u4e0d\u540c\u7684\u60c5\u51b5\u8c03\u7528\u5bf9\u5e94\u7684 Allocator \u6765\u8fdb\u884c\u5f15\u64ce\u7684\u5185\u5b58\u5206\u914d\u3002<\/p>\n<p>\u4f8b\u5982\u6211\u4eec\u53ef\u4ee5\u4ee5 Unity 3D Game Kit \u8fd9\u4e2a\u514d\u8d39\u9879\u76ee\u4e3a\u4f8b\uff0c\u4f7f\u7528 Instrument \u6765\u67e5\u770b\u4e00\u4e0b\u5b83\u7684\u5185\u5b58\u5206\u914d\u3002<\/p>\n<p>\u53ef\u4ee5\u770b\u5230 MemoryManager \u8c03\u7528\u4e86 UnityDefaultAllocator\u3002 \u800c\u4e0b\u56fe\u7684\u8fd9\u4e2a\u5206\u914d\u5219\u4f7f\u7528\u4e86 IphoneNewLabelAllocator \u6765\u5206\u914d\u5185\u5b58\u3002<\/p>\n<p>\u4e5f\u5c31\u662f\u8bf4 Unity \u7684\u4ee3\u7801\u5206\u914d\u7684\u5185\u5b58\uff0cUnity \u662f\u4f1a\u8fdb\u884c\u8bb0\u5f55\u7684\u3002\u4f46\u662f\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u9664\u4e86 Unity \u7684\u4ee3\u7801\u672c\u8eab\u5206\u914d\u7684\u5185\u5b58\uff0c\u8fd8\u6709\u5f88\u591a framework \u6216\u8005\u7b2c\u4e09\u65b9 library \u4e5f\u4f1a\u5206\u914d\u5185\u5b58\u3002\u4f46\u662f\u8fd9\u90e8\u5206\u5185\u5b58\uff0cUnity \u7684 Profiler \u662f\u4e0d\u4f1a\u8bb0\u5f55\u7684\u3002 0x02 \u4f7f\u7528 Instrument \u8c03\u8bd5 Unity \u6e38\u620f\u7684\u5185\u5b58<\/p>\n<p>\u8fd9\u90e8\u5206\u6211\u63a8\u8350 Valentin Simonov \u7684\u8fd9\u7bc7\u6587\u7ae0 Understanding iOS Memory (WiP)\uff0c\u5bf9\u4f7f\u7528 Instrument \u8c03\u8bd5\u5185\u5b58\u4ecb\u7ecd\u7684\u5341\u5206\u6e05\u6670\u3002 0x03 \u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u6df1\u5165\u6316\u6398\u5185\u5b58\u95ee\u9898<\/p>\n<p>\u9664\u4e86\u4f7f\u7528 Instrument \u6765\u8c03\u67e5\u5185\u5b58\u95ee\u9898\u4e4b\u5916\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u901a\u8fc7\u5f88\u68d2\u7684 Xcode memory debugger \u5de5\u5177\u6765\u67e5\u627e\u5185\u5b58\u95ee\u9898\u3002\u5c24\u5176\u662f\u5c06 Memgraph \u5bfc\u51fa\u540e\uff0c\u8fd8\u53ef\u4ee5\u501f\u52a9\u5404\u79cd\u547d\u4ee4\u884c\u5de5\u5177\u6765\u8f85\u52a9\u8c03\u67e5\u4ee5\u83b7\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n<p>\u800c\u4e14\u6709\u65f6\u5927\u5bb6\u4e5f\u4f1a\u62b1\u6028\u8bf4\u5728 Xcode \u7684 Memory Report \u9875\u9762\u770b\u5230\u7684\u5185\u5b58\u6570\u636e\u6709\u65f6\u5019\u4e0d\u4ec5\u548c Unity Profiler \u4e0d\u4e00\u6837\uff0c\u6709\u65f6\u751a\u81f3\u548c Instrument \u7b49\u82f9\u679c\u81ea\u5df1\u7684\u6027\u80fd\u5de5\u5177\u6570\u503c\u4e5f\u4e0d\u4e00\u6837\u3002\u4e0a\u6587\u5df2\u7ecf\u8bf4\u8fc7\u4e86\uff0c\u4e0d\u540c\u7684\u5de5\u5177\u6709\u4e0d\u540c\u7684\u6570\u636e\u662f\u6b63\u5e38\u7684\u3002\u4f46\u662f\u6211\u4eec\u540c\u6837\u53ef\u4ee5\u901a\u8fc7 Memgraph \u548c\u547d\u4ee4\u884c\u5de5\u5177\u6765\u67e5\u770b\u4e00\u4e0b\uff0cMemory Report \u7684\u6570\u636e\u4fa7\u91cd\u4ec0\u4e48\u5185\u5bb9\u3002 \u8fd8\u662f\u4ee5 Unity 3D Kit \u8fd9\u4e2a\u5de5\u7a0b\u4f5c\u4e3a\u6f14\u793a\uff0c\u6d4b\u8bd5\u8bbe\u5907\u4e3a iPhone X\uff0c\u4e0d\u8fc7\u5728\u5f00\u59cb\u4e4b\u524d\u6211\u4eec\u9996\u5148\u9700\u8981\u5f00\u542f Scheme -&gt; Run -&gt; Diagnostics -&gt; Malloc Stack \u9009\u9879\u3002<\/p>\n<p>\u8fd0\u884c\u6e38\u620f\u540e\u4ece\u4e3b\u83dc\u5355\u70b9\u51fb\u5f00\u59cb\u6e38\u620f\u52a0\u8f7d\u7b2c\u4e00\u4e2a\u573a\u666f\uff0c\u6211\u4eec\u53ef\u4ee5\u5728 Memory Report \u4e2d\u770b\u5230\u6b64\u65f6\u7684\u5185\u5b58\u5df2\u7ecf\u8fbe\u5230\u4e86 1.48G \u3002\u4f46\u662f Memory Report \u4e2d\u5b83\u7684\u5185\u5b58\u523b\u5ea6\u4ecd\u7136\u5728\u7eff\u8272\u90e8\u5206\uff0c\u6240\u4ee5\u5b9e\u4e8b\u6c42\u662f\u7684\u8bb2 Memory Report \u7684\u523b\u5ea6\u5e76\u4e0d\u662f\u4e00\u4e2a\u597d\u7684\u4f18\u5316\u5efa\u8bae\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u5185\u5b58\u5f00\u9500\u5728 iphone7 \u4e0a\u5c31\u76f4\u63a5\u4f1a\u5bfc\u81f4\u6e38\u620f\u88ab\u7cfb\u7edf\u4e2d\u6b62\u3002<\/p>\n<p>Animation Leak?<\/p>\n<p>\u6211\u4eec\u76f4\u63a5\u8fdb\u5165\u5230 Xcode memory debugger\uff0c\u5982\u679c\u60f3\u8981\u5728\u8fd9\u91cc\u68c0\u67e5\u662f\u5426\u6709\u5185\u5b58 leak \u7684\u95ee\u9898\uff0c\u53ef\u4ee5\u70b9\u51fb Filter \u4e2d\u7684\u9009\u9879\u3002\u8fd9\u91cc\u6709\u4e00\u4e2a\u5e38\u89c1\u7684\u5047\u201cleak\u201d\u60c5\u51b5\u3002<\/p>\n<p>\u5982\u679c\u6211\u4eec\u770b\u4e00\u4e0b\u5b83\u7684\u5806\u6808\u4fe1\u606f\u7684\u8bdd\uff0c\u5927\u591a\u662f\u548c Animation \u6709\u5173\u7684\u3002\u8fd9\u91cc\u6211\u54a8\u8be2\u4e86\u4e00\u4e0b\u8fd9\u4e2a\u529f\u80fd\u7684\u5f00\u53d1\u8005\uff0c\u786e\u8ba4\u8fd9\u662f\u4e00\u4e2a\u82f9\u679c\u7684\u8bef\u62a5\uff0cUnity \u8fd8\u662f\u4f1a\u6b63\u5e38\u91ca\u653e\u8fd9\u90e8\u5206\u5185\u5b58\u7684\u3002\u5f53\u7136\u5982\u679c\u5927\u5bb6\u9047\u5230\u5176\u4ed6\u5947\u602a\u7684\u548c\u5f15\u64ce\u6709\u5173\u7684 leak\uff0c\u53ef\u4ee5\u6309\u7167\u8fd9\u7bc7\u6587\u7ae0\u7684\u4ecb\u7ecd\u7ed9 Unity \u63d0\u4ea4 Bug Report\u3002 https:\/\/blogs.unity3d.com\/2016\/08\/24\/attaching-your-project-to-a-bug-report\/ \u4e4b\u540e\u6211\u4eec\u53ef\u4ee5\u5c06\u6b64\u65f6\u7684\u6570\u636e\u5bfc\u51fa\u4e3a.memgraph \u6587\u4ef6\u3002\u63a5\u4e0b\u6765\u5c31\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u547d\u4ee4\u884c\u5de5\u5177\u6765\u5904\u7406\u8fd9\u4e9b\u6570\u636e\u4e86\u3002<\/p>\n<p>VMMAP Summary<\/p>\n<p>\u7b2c\u4e00\u4e2a\u547d\u4ee4\u884c\u5de5\u5177\u662f vmmap\uff0c\u4f7f\u7528\u5b83\u6211\u4eec\u53ef\u4ee5\u67e5\u770b\u5f53\u524d\u7684\u865a\u62df\u5185\u5b58\u7684\u6570\u636e\u3002 \u9996\u5148\u62ff\u5230\u4e00\u4e2a memgraph \u6587\u4ef6\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u8fd9\u4e2a\u6307\u4ee4\u540c\u65f6\u52a0\u4e0a&#8211;summary \u6807\u8bb0\u6765\u8f93\u51fa\u5f53\u524d\u865a\u62df\u5185\u5b58\u7684\u4e00\u4e2a\u603b\u89c8\u3002 vmmap &#8211;summary Unity3DKit_ipx.memgraph \u7ec8\u7aef\u7684\u8f93\u51fa\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\u4e00\u4e9b\u6709\u8da3\u7684\u5730\u65b9\u3002\u9996\u5148\u6709\u524d 4 \u5217\u662f\u6211\u4eec\u4e4b\u524d\u8ba8\u8bba\u8fc7\u7684\u5185\u5bb9\uff1aVIRTUAL SIZE\u3001RESIDENT SIZE\u3001DIRTY SIZE\u3001SWAPPED SIZE\u3002\u5206\u522b\u8868\u793a\u865a\u62df\u5185\u5b58\u7684\u5927\u5c0f\uff0c\u6620\u5c04\u5230\u7269\u7406\u5185\u5b58\u7684\u5927\u5c0f\uff0cDirty \u5185\u5b58\u7684\u5927\u5c0f\u4ee5\u53ca Compressed \u5185\u5b58\u7684\u5927\u5c0f\u3002 \u6211\u4eec\u53ef\u4ee5\u770b\u5230 TOTAL \u7684\u90e8\u5206\uff0c\u8fd9\u4e2a\u6e38\u620f\u8fdb\u7a0b\u5206\u914d\u4e86 2.7G \u7684\u865a\u62df\u5185\u5b58\u5176\u4e2d\u6709 1.6G \u6620\u5c04\u5230\u4e86\u7269\u7406\u5185\u5b58\u4e0a\uff0c\u800c DIRTY SIZE \u7684\u503c\u662f 1.4G\u2014\u2014\u8fd9\u4e2a\u503c\u5f88\u63a5\u8fd1 Memory Report \u4e2d\u7684\u6570\u503c\uff0c\u800c SWAPPED SIZE \u7684\u6570\u503c\u4e3a 52mb\uff0c\u6839\u636e\u82f9\u679c\u5de5\u7a0b\u5e08\u5728 WWDC2018 \u4e0a\u7684\u6f14\u8bb2\uff0c\u8fd9\u4e2a\u503c\u662f\u538b\u7f29\u524d\u7684\u5185\u5b58\u800c\u4e0d\u662f\u538b\u7f29\u540e\u7684\u5185\u5b58\u3002\u56e0\u6b64\u6211\u4eec\u4e3b\u8981\u6765\u5173\u6ce8 DIRTY SIZE \u8fd9\u4e00\u9879\u3002 IOKit<\/p>\n<p>\u5176\u6b21\u6211\u4eec\u53ef\u4ee5\u770b\u5230 IOKit \u7684\u5f00\u9500\u6700\u5927\uff0c\u5b83\u7684\u865a\u62df\u5185\u5b58\u4e0d\u4ec5\u8fbe\u5230\u4e86 832.5mb \uff0c\u800c\u4e14\u5b9e\u9645\u6620\u5c04\u5230\u7269\u7406\u5185\u5b58\u4e0a\u7684\u7a7a\u95f4\u4e5f\u8fbe\u5230\u4e86 750.4mb \u3002\u8fd9\u90e8\u5206\u4e3b\u8981\u662f\u4e00\u4e9b\u548c GPU \u76f8\u5173\u7684\u4e00\u4e9b\u5185\u5b58\uff0c\u4f8b\u5982 render targets, textures, meshes, compiled shaders \u7b49\u7b49\u3002\u800c\u8fd9\u4e2a\u6d4b\u8bd5\u9879\u76ee\u4e5f\u7684\u786e\u662f mesh\u3001texture \u7684\u5185\u5b58\u5360\u7528\u5f88\u5927\u3002 MALLOC \u548c Heap<\/p>\n<p>\u518d\u6b21\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230 MALLOC_**\u5206\u914d\u4e86\u5f88\u591a\u5185\u5b58\u3002\u8fd9\u90e8\u5206\u5185\u5b58\u4e3b\u8981\u662f\u8c03\u7528 Malloc \u8fdb\u884c\u5206\u914d\u7684\uff0c\u5176\u4e2d\u5373\u5305\u62ec Unity \u7684\u539f\u751f\u4e5f\u5c31\u662f C++\u4ee3\u7801\u7684\u5206\u914d\u4e5f\u5305\u62ec\u7b2c\u4e09\u65b9\u5e93\u548c\u7cfb\u7edf\u4f7f\u7528 Malloc \u5206\u914d\u7684\u5185\u5b58\uff0c\u8fd9\u90e8\u5206\u5185\u5b58\u5728\u6240\u8c13\u7684 Heap \u4e0a\uff0c\u5728\u8fd9\u51e0\u884c\u7684\u540e\u9762\u53ef\u4ee5\u770b\u5230\u201csee MALLOC ZONE table below\u201d\uff0c\u4e5f\u5c31\u662f\u53ef\u4ee5\u5728\u4e0b\u9762\u770b\u5230\u5404\u4e2a heap zone \u7684\u4e00\u4e2a\u5f52\u7c7b\u3002\u5728\u8fd9\u91cc\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u7b2c\u4e8c\u4e2a\u547d\u4ee4\u884c\u5de5\u5177 heap \u6765\u68c0\u67e5\u4e00\u4e0b Heap \u5185\u5b58\u7684\u5185\u5bb9\u3002 heap &#8211;sortBySize Unity3DKit_ipx.memgraph \u4f7f\u7528 heap \u6307\u4ee4\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u6dfb\u52a0&#8211;sortBySize \u6807\u5fd7\u6765\u5bf9\u6570\u636e\u8fdb\u884c\u6392\u5e8f\uff08\u9ed8\u8ba4\u6309\u7167\u7c7b\u578b\u5b9e\u4f8b\u7684\u6570\u91cf\u8fdb\u884c\u6392\u5e8f\uff09\u3002<\/p>\n<p>\u53ef\u4ee5\u770b\u5230 Heap \u7684\u7edd\u5927\u90e8\u5206\u5185\u5b58\u90fd\u88ab non-object \u5360\u7528\u4e86\uff0c\u8fbe\u5230\u4e86\u8fd1 700mb\uff0c\u800c\u5b9e\u9645\u7684 object \u7684\u5185\u5b58\u5206\u914d\u5176\u5b9e\u90fd\u662f\u5f88\u5c0f\u7684\uff0c\u6bd4\u5982\u7c7b GpuProgramMetal \u7684\u5b9e\u4f8b\u6709 573 \u4e2a\uff0c\u4f46\u662f\u5185\u5b58\u5176\u5b9e\u53ea\u5360\u7528\u4e86 223kb\u3002\u6b64\u65f6\u5927\u5bb6\u4e00\u5b9a\u5bf9 non-object \u7684\u5185\u5bb9\u5f88\u611f\u5174\u8da3\uff0c\u4e0d\u8fc7\u5728\u8fd9\u4e2a\u9875\u9762\u91cc\u4f3c\u4e4e\u4e5f\u770b\u4e0d\u5230\u592a\u591a\u7684\u5185\u5bb9\u3002\u6240\u4ee5\u63a5\u4e0b\u6765\u6211\u4eec\u53ef\u4ee5\u6dfb\u52a0&#8211;showSize \u6807\u5fd7\uff0c\u5c06\u5408\u5e76\u5728\u4e00\u8d77\u7684\u6570\u636e\u6309\u7167 size \u8fdb\u884c\u5206\u7ec4\u3002 heap &#8211;showSize &#8211;sortBySize Unity3DKit_ipx.memgraph \u8fd9\u6837\u5c31\u6e05\u6670\u591a\u4e86\u3002<\/p>\n<p>\u53ef\u4ee5\u770b\u5230 non-object \u8fd9\u4e00\u7c7b\u4e2d\uff0c\u6392\u540d\u6700\u9ad8\u7684\u51e0\u5757\u5185\u5b58\u5206\u914d\u7684\u5c3a\u5bf8\u5206\u522b\u662f 1 \u4e2a 31mb\u30013 \u4e2a 10mb \u4ee5\u53ca 1 \u4e2a 8.4mb \uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u786e\u5b9a\u4e86\u8fd9\u4e2a\u65f6\u5019\u7684\u8c03\u67e5\u65b9\u5411\u3002 \u5f53\u7136\uff0cheap \u6307\u4ee4\u8fd8\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u529f\u80fd\uff0c\u6bd4\u5982\u90a3\u4e9b\u6709 Class Name \u7684\u5bf9\u8c61\u5206\u914d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7 ClassName \u5339\u914d\u7684\u65b9\u5f0f\u83b7\u53d6\u6bcf\u4e00\u4e2a\u8be5\u7c7b\u578b\u5b9e\u4f8b\u7684\u5185\u5b58\u5730\u5740\u3002\u6b64\u65f6\u9700\u8981-addresses \u6807\u7b7e\u5373\u53ef\u3002\u6bd4\u5982\u6211\u4eec\u8f93\u51fa Unity \u7684 GpuProgramMetal \u7c7b\u7684\u6240\u6709\u5b9e\u4f8b\u7684\u5730\u5740\u4fe1\u606f\uff0c\u53ef\u4ee5\u770b\u5230\u5176\u5b9e\u8fd9\u4e2a\u7c7b\u7684\u5b9e\u4f8b\u672c\u8eab\u5e76\u4e0d\u5927\uff0c\u4f46\u662f\u5b83\u5f15\u7528\u7684\u771f\u6b63\u7684 shader \u8d44\u6e90\u5219\u53ef\u80fd\u662f\u5185\u5b58\u5f00\u9500\u7684\u5927\u6237\u4e4b\u4e00\u3002 heap -addresses GpuProgramMetal Unity3DKit_ipx.memgraph<\/p>\n<p>\u540c\u65f6\uff0c\u6709\u4e86\u5404\u4e2a\u5bf9\u8c61\u6240\u5728\u7684\u5185\u5b58\u5730\u5740\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762\u8981\u63d0\u5230\u7684 malloc_history \u547d\u4ee4\u6765\u67e5\u627e\u5b83\u4eec\u662f\u600e\u4e48\u6765\u7684\u3002\u4f46\u662f\u73b0\u5728\u6211\u4eec\u8fd8\u662f\u628a\u76ee\u5149\u8f6c\u5411\u5185\u5b58\u5206\u914d\u6bd4\u8f83\u5927\u7684\u76ee\u6807\u5427\u3002 \u6b64\u65f6\u8fd4\u56de\u7ec8\u7aef\uff0c\u7ee7\u7eed\u8f93\u51fa\u865a\u62df\u5185\u5b58\u7684\u4fe1\u606f\uff0c\u4e0d\u8fc7\u8fd9\u6b21\u6211\u4eec\u53ea\u5173\u6ce8 MALLOC_LARGE \u7684\u5206\u914d\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u501f\u52a9 grep \u6765\u8fc7\u6ee4\u51fa\u6211\u4eec\u7684\u76ee\u6807\u3002 vmmap -verbose Unity3DKit_ipx.memgraph | grep &#8220;MALLOC_LARGE&#8221; \u8fd9\u6b21\u8f93\u51fa\u4e86 MALLOC_LARGE \u7c7b\u578b\u4e0b\u7684\u5185\u5b58\u4fe1\u606f\uff0c\u5305\u62ec\u5b83\u7684\u5730\u5740\u3001\u5c3a\u5bf8\u4ee5\u53ca\u6240\u5728 Heap Zone \u7b49\u7b49\u4fe1\u606f\u3002\u6211\u4eec\u53ef\u4ee5\u5728\u8fd9\u91cc\u627e\u5230\u6211\u4eec\u7684\u76ee\u6807\uff0c\u4e00\u4e2a 30mb\u30013 \u4e2a 10mb \u4ee5\u53ca\u4e00\u4e2a 8mb \u7684\u5185\u5b58\u5206\u914d\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u5c31\u6765\u770b\u4e00\u4e0b\u5206\u914d\u5b83\u4eec\u7684\u5806\u6808\u8c03\u7528\u5427\u3002\u8fd9\u91cc\u6211\u4eec\u4f1a\u4f7f\u7528 malloc_history \u547d\u4ee4\uff0c\u540c\u65f6\u52a0\u4e0a&#8211;fullStacks \u6807\u5fd7\u6765\u8f93\u51fa\u5806\u6808\u4fe1\u606f\u3002 malloc_history Unity3DKit_ipx.memgraph &#8211;fullStacks 0x0000000127c60000 \u53ef\u4ee5\u770b\u5230\u8fd9 30mb \u7684\u5206\u914d\u662f\u4e3a\u4e86\u7ed9 FMOD \u5206\u914d\u5185\u5b58\u6c60\u3002<\/p>\n<p>\u53e6\u5916 3 \u4e2a 10mb \u7684\u5206\u914d\uff0c\u540c\u6837\u4e5f\u662f\u505a\u7c7b\u4f3c\u7684\u4e8b\u60c5\u3002\u53ef\u89c1\u8fd9\u4e2a\u9879\u76ee\u4f7f\u7528\u7684\u58f0\u97f3\u8d44\u6e90\u5f88\u591a\u3002\u6700\u540e\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u8fd9\u4e2a 8mb \u7684\u5206\u914d\u662f\u4ece\u54ea\u91cc\u6765\u7684\u3002 malloc_history Unity3DKit_ipx.memgraph &#8211;fullStacks 0x0000000113400000<\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u662f\u5f00\u542f\u591a\u7ebf\u7a0b\u6e32\u67d3\u65f6\uff0cUnity \u521b\u5efa CommandQueue \u65f6\u5206\u914d\u7684\u5185\u5b58\u3002 VM_ALLOC == Mono Size?<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230 vmmap \u2013summary \u8f93\u51fa\u7684\u7ed3\u679c\u4e2d\uff0c\u6709\u4e00\u9879\u53eb\u505a VM_ALLOC\u3002\u6839\u636e Valentin Simonov \u7684\u8bf4\u6cd5\uff0cVM_ALLOC \u5bf9\u5e94\u7684\u662f Mono \u5185\u5b58\u4e5f\u5c31\u662f\u6258\u7ba1\u5185\u5b58\u7684\u5927\u5c0f\u3002\u7a76\u7adf\u662f\u5426\u5982\u6b64\u5462\uff1f\u6211\u4eec\u540c\u6837\u53ef\u4ee5\u901a\u8fc7\u4e0a\u9762\u7684\u65b9\u5f0f\uff0c\u6765\u67e5\u770b\u4e00\u4e0b VM_ALLOC \u90e8\u5206\u7684\u5185\u5b58\u5206\u914d\u5806\u6808\u3002 \u9996\u5148\u6211\u4eec\u8fd8\u662f\u901a\u8fc7 vmmap \u548c grep \u6765\u8fc7\u6ee4\u51fa VM_ALLOC \u90e8\u5206\u7684\u5185\u5b58\u4fe1\u606f\u3002 vmmap -verbose Unity3DKit_ipx.memgraph | grep &#8220;VM_ALLOC&#8221; \u53ef\u4ee5\u770b\u5230\u8fd9\u90e8\u7684\u5185\u5b58\u5206\u914d\u5e76\u4e0d\u591a\uff0c\u6211\u4eec\u540c\u6837\u9009\u62e9 2 \u5757\u5206\u914d\u6700\u5927\u7684\u5185\u5b58\u4e0b\u624b\u3002<\/p>\n<p>\u6211\u4eec\u9996\u5148\u4f7f\u7528 malloc_history \u6765\u67e5\u770b\u4e00\u4e0b 3m \u90e8\u5206\u7684\u8c03\u7528\u5806\u6808\u3002 malloc_history Unity3DKit_ipx.memgraph &#8211;fullStacks 0x0000000152bd4000<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u8fd9 3m \u7684\u5185\u5b58\u662f C#\u811a\u672c\u4e2d\u8c03\u7528\u4e86 SimplFXSynth \u7684 RenderAudio \u65b9\u6cd5\u800c\u89e6\u53d1\u4e86 GC \u5206\u914d\uff0c\u6258\u7ba1\u5806\u8fdb\u884c\u4e86\u6269\u5bb9\u3002\u9488\u5bf9\u811a\u672c\u4e2d\u7684\u65b9\u6cd5\u5b9a\u4f4d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7 RuntimeInvoker \u8fd9\u4e2a\u7b26\u53f7\u6765\u5b9a\u4f4d\u5b83\u5728\u5806\u6808\u4e2d\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>\u6709\u8da3\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u518d\u6765\u770b\u770b 1mb \u7684\u8fd9\u5757\u5185\u5b58\u662f\u600e\u4e48\u5206\u914d\u7684\u3002 malloc_history Unity3DKit_ipx.memgraph &#8211;fullStacks 0x0000000150084000 \u8fd9\u6b21\u662f\u7531\u4e8e Unity \u7684 ScriptingGCHandle::Acquire \u65b9\u6cd5\u5728\u6258\u7ba1\u5806\u4e0a\u8fdb\u884c\u4e86\u5185\u5b58\u5206\u914d\u3002<\/p>\n<p>\u53ef\u89c1\uff0cVM_ALLOC \u8fd9\u90e8\u5206\u5185\u5b58\u4e3b\u8981\u5bf9\u5e94\u4e86 Unity \u7684 Mono \u6258\u7ba1\u5806\u7684\u5185\u5b58\u800c\u4e14\u8fd9\u4e2a\u9879\u76ee\u7684 Mono \u5185\u5b58\u5e76\u4e0d\u5927\u3002\u800c\u5177\u4f53\u662f\u54ea\u4e2a\u51fd\u6570\u89e6\u53d1\u4e86 GC \u5206\u914d\uff0c\u5219\u53ef\u4ee5\u901a\u8fc7 malloc_history \u6765\u67e5\u770b\u3002 Command Summary<\/p>\n<p>\u81f3\u6b64\uff0c\u4f7f\u7528\u547d\u4ee4\u884c\u8c03\u8bd5\u548c\u67e5\u627e iOS \u5e73\u53f0\u4e0a\u5185\u5b58\u95ee\u9898\u5c31\u4ecb\u7ecd\u5b8c\u4e86\u3002\u7b80\u5355\u6765\u4e2a\u5c0f\u7ed3\uff0c\u62ff\u5230\u4e00\u4e2a Unity \u6e38\u620f\u7684\u5185\u5b58.Memgraph \u6587\u4ef6\u4e4b\u540e\uff0c\u53ef\u4ee5\u5148\u901a\u8fc7 vmmap &#8211;summary \u6765\u67e5\u770b\u4e00\u4e0b\u5185\u5b58\u7684\u5168\u666f\u56fe\u3002\u5bf9\u4e8e heap \u4e5f\u5c31\u662f malloc \u5206\u914d\u7684\u5185\u5b58\uff0c\u53ef\u4ee5\u8fdb\u4e00\u6b65\u901a\u8fc7 heap \u6307\u4ee4\u6765\u8fdb\u4e00\u6b65\u5206\u6790\u3002 \u800c\u4e00\u65e6\u83b7\u53d6\u4e86\u76ee\u6807\u5bf9\u8c61\u7684\u5185\u5b58\u5730\u5740\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528 malloc_history \u6307\u4ee4\u6765\u83b7\u53d6\u5206\u914d\u8fd9\u5757\u5185\u5b58\u7684\u5806\u6808\u4fe1\u606f\u4e86\u3002\u5f53\u7136\u524d\u63d0\u662f\u8981\u5f00\u542f Malloc Stack \u7684\u9009\u9879\u3002\u4e4b\u540e\uff0c\u53ef\u4ee5\u505a\u4e00\u4e2a\u81ea\u52a8\u5316\u7684\u5206\u6790\u5de5\u5177\uff0c\u5bf9\u6570\u636e\u8fdb\u884c\u5904\u7406\u548c\u8f93\u51fa\u6765\u5b9a\u4f4d\u5185\u5b58\u95ee\u9898\u3002<\/p>\n<p>0x04 \u5c0f\u5f69\u86cb<\/p>\n<p>Unity 3D Game Kit \u662f\u4e00\u4e2a\u5f88\u68d2\u7684 Unity \u7684\u5b66\u4e60\u5de5\u7a0b\u3002\u5b83\u7684\u6559\u5b66\u9875\u9762\u53ef\u4ee5\u67e5\u770b\u8fd9\u91cc\uff1a https:\/\/learn.unity.com\/tutorial\/3d-game-kit-reference-guide#5c7f8528edbc2a002053b73f<\/p>\n<p>iOS13 \u4e4b\u540e\u63d0\u4f9b\u4e86\u4e00\u4e2a\u65b0\u7684 API-os_proc_available_memory\uff0c\u5229\u7528\u8fd9\u4e2a API \u6211\u4eec\u53ef\u4ee5\u83b7\u53d6\u5f53\u524d\u8fd9\u4e2a\u8fdb\u7a0b\u8fd8\u80fd\u83b7\u53d6\u591a\u5c11\u5185\u5b58\u7684\u9884\u4f30\u503c\u3002\u55ef\uff0c\u602a\u4e0d\u5f97\u6211\u7684 iphone7 \u8dd1\u4e0d\u52a8\u8fd9\u4e2a\u9879\u76ee\u3002<\/p>\n<p>\u539f\u6587\u94fe\u63a5\uff1a https:\/\/connect.unity.com\/p\/xie-gei-unitykai-fa-zhe-de-iosnei-cun-diao-shi-zhi-nan?app=true \u66f4\u591a\u5e72\u8d27\u8d44\u6e90\u5b66\u4e60\uff0c\u6233\u4e0a\u65b9\u94fe\u63a5\u4e0b\u8f7d Unity \u5b98\u65b9 app\uff0c\u5728\u7ebf\u6280\u672f\u4e92\u52a8\u7b54\u7591\uff0c\u7ed3\u8bc6\u66f4\u591a Unity \u5c0f\u4f19\u4f34\uff0c\u4ea4\u53cb\u5b66\u4e60\u4e24\u4e0d\u8bef\uff01<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>0<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5199\u7ed9 Unity \u5f00\u53d1\u8005\u7684 iOS&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/95867"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=95867"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/95867\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=95867"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=95867"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=95867"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}