【问题标题】:How to get available memory in IOS using Xamarin如何使用 Xamarin 在 IOS 中获取可用内存
【发布时间】:2017-01-26 06:52:49
【问题描述】:

我正在移植我过去使用 Appcelerator 构建的应用程序。这个应用程序创建了大量的动态内容,因此有一个功能可以查看内存。换句话说:类似的解释:使用 DidReceiveMemoryWarning() 清除缓存或使用外部工具查看内存不适用。最终用户必须观察您的动态内容消耗的大小和重量。使用 Appcelerator 制作的应用程序使用 Titanium.Platform.availableMemory,它非常易于使用。

我不敢相信使用 Xamarin 是不可能的。真的不可能吗?我发现了一个从 Objective-C 转换为 .Net 的库,但它可能很旧,因为它无法编译。

在这个意义上有什么帮助吗?

【问题讨论】:

    标签: xamarin xamarin.ios


    【解决方案1】:

    您可以使用System.GC.GetTotalMemory(false); 获取当前内存。如果需要可用内存,可以使用NSProcessInfo.ProcessInfo.PhysicalMemory。然后,您可以覆盖您自己的 DidReceiveMemoryWarning() 行为以清理多余的资源。

    前任:

    public override void DidReceiveMemoryWarning ()
    {
        photoMap.Clear ();
        View = null;
        photoImageView = null;
        toolbar = null;
        syncIsNeeded = true;
        base.DidReceiveMemoryWarning();
    }
    

    【讨论】:

    • 但这是“使用的内存”,对吗?我可以假设我的可用内存是 NSProcessInfo.ProcessInfo.PhysicalMemory - System.GC.GetTotalMemory(false) 吗?
    • 是的,那是用过的内存。可通过NSProcessInfo.ProcessInfo.PhysicalMemory 完成。但要记住的一件事是 Titanium Mobile 的实现可能与这些项目不同。这是来源:github.com/appcelerator/titanium_mobile/blob/…
    • 泰!我会做一些压力测试!
    猜你喜欢
    • 2012-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-19
    • 2020-01-21
    • 2019-03-02
    • 1970-01-01
    相关资源
    最近更新 更多