【问题标题】:Detecting memory leak in cocos2dx project for WP8检测 WP8 的 cocos2dx 项目中的内存泄漏
【发布时间】:2013-10-08 11:31:50
【问题描述】:

我想在 windows phone 8 的 cocos2dx 应用程序中找到一些内存泄漏。IDE 是 Visual Studio Express 2012。我看到了 app profiling 的链接。但正如页面上所写,“只有执行选项可用于 Direct3D 应用程序”。我无法弄清楚内存分析的选项,因为cocos2dx 在 windows phone 中使用了 directx。我应该如何检测内存泄漏?

【问题讨论】:

  • 我也遇到了这个问题,我的 wp8 的 cocos2d-x 应用程序很快就耗尽了内存...

标签: memory windows-phone-8 memory-leaks cocos2d-x


【解决方案1】:

您可以通过以下代码检测应用程序内存使用情况。 在 App.xaml.cs 中添加以下代码

公共部分类应用程序:应用程序 {

    private static Timer timer = null;
    public static void BeginRecording()
    {

        if (System.Diagnostics.Debugger.IsAttached)
        {
            // start a timer to report memory conditions every 2 seconds
            timer = new Timer(state =>
            {
                // every 2 seconds do something 
                string report =
                DateTime.Now.ToLongTimeString() + " memory conditions: " +
                Environment.NewLine +
                "\tApplicationCurrentMemoryUsage: " +
                    getExactValue(DeviceStatus.ApplicationCurrentMemoryUsage) + " MB" +
                    Environment.NewLine +
                "\tApplicationPeakMemoryUsage: " +
                    getExactValue(DeviceStatus.ApplicationPeakMemoryUsage) + " MB" +
                    Environment.NewLine +
                "\tApplicationMemoryUsageLimit: " +
                    getActualValue(DeviceStatus.ApplicationMemoryUsageLimit) + " MB" +
                    Environment.NewLine +
                "\tDeviceTotalMemory: " + getActualValue(DeviceStatus.DeviceTotalMemory) + " MB" + Environment.NewLine +
                "\tApplicationWorkingSetLimit: " +
                    getActualValue(Convert.ToInt64(DeviceExtendedProperties.GetValue("ApplicationWorkingSetLimit"))) + " MB" +
                    Environment.NewLine;

                // write to IsoStore or debug conolse
                Debug.WriteLine(report);
            },
            null,
            TimeSpan.FromSeconds(2),
            TimeSpan.FromSeconds(2));
        }
    }
    public static decimal getExactValue(long stats)
    {
        return Math.Round(((decimal)(stats) / (decimal)(1048576.00)), 2);
    }

    public static int getActualValue(long stats)
    {
        return ((int)Math.Ceiling(getExactValue(stats)));
    }

现在调用 application_launching 中的 BeginRecording() 函数。 这将在每 2 秒后为您提供准确的内存统计信息,并且您可以识别内存泄漏。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-16
    • 2015-03-07
    • 1970-01-01
    • 1970-01-01
    • 2011-05-12
    • 1970-01-01
    相关资源
    最近更新 更多