0%

Mac下处理MAT(Memory Analyzer Tool)报错的问题

当程序出现内存泄露(Out of memory)时,我们需要通过Eclipse的Memory Analyzer Tool去定位错误的代码。

从Eclipse官网下载MAT,https://www.eclipse.org/mat/downloads.php

选择不同操作的版本。

1
2
3
4
5
6
7
8
9
10
11
12
Memory Analyzer 1.8.1 Release
Version: 1.8.1.20180910 | Date: 19 September 2018 | Type: Released
Update Site: http://download.eclipse.org/mat/1.8.1/update-site/
Archived Update Site: MemoryAnalyzer-1.8.1.201809100846.zip
Stand-alone Eclipse RCP Applications
Windows (x86)
Windows (x86_64)
Mac OSX (Mac/Cocoa/x86_64)
Linux (x86/GTK+)
Linux (x86_64/GTK+)
Linux (PPC64/GTK+)
Linux (PPC64le/GTK+)

当我在Mac系统双击mat.app打开MAT时,系统报错,查看日志内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
!SESSION 2019-04-18 21:48:21.506 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.8.0_92
java.vendor=Oracle Corporation
BootLoader constants: OS=macosx, ARCH=x86_64, WS=cocoa, NL=zh_CN
Framework arguments: -keyring /Users/simon/.eclipse_keyring
Command-line arguments: -os macosx -ws cocoa -arch x86_64 -keyring /Users/simon/.eclipse_keyring

!ENTRY org.eclipse.osgi 4 0 2019-04-18 21:48:24.893
!MESSAGE Application error
!STACK 1
java.lang.IllegalStateException: The platform metadata area could not be written: /private/var/folders/cl/kn5ppbpd28j0s6y5kcxm9rdm0000gn/T/AppTranslocation/8157A927-01B7-4CF8-8F8B-AA4530391F8A/d/mat.app/Contents/MacOS/workspace/.metadata. By default the platform writes its content
under the current working directory when the platform is launched. Use the -data parameter to
specify a different content area for the platform.
at org.eclipse.core.internal.runtime.DataArea.assertLocationInitialized(DataArea.java:70)
...

查看日志,分析原因,我们得知其中一个文件无写入权限。IllegalStateException: The platform metadata area could not be written.

我们可以指定一个具有写入权限的文件夹,设置如下:

编辑文件 /Applications/mat.app/Contents/Eclipse/MemoryAnalyzer.ini

添加-data参数:

1
2
-data
/Users/simon/workspace

data参数和路径必须在两个不同的行,data参数必须放在Laucher之前。

最终文件内容如下所示:

1
2
3
4
5
6
7
8
9
10
-startup
../Eclipse/plugins/org.eclipse.equinox.launcher_1.5.0.v20180512-1130.jar
-data
/Users/simon/workspace
--launcher.library
../Eclipse/plugins/org.eclipse.equinox.launcher.cocoa.macosx.x86_64_1.1.700.v20180518-1200
-vmargs
-Xmx1024m
-Dorg.eclipse.swt.internal.carbon.smallFonts
-XstartOnFirstThread

保存文件后,再次双击启动MAT,软件可以成功打开了。