正常的内存 ram 大小是多少?(xamarin) [英] What is the normal memory-ram size?(xamarin)

查看:46
本文介绍了正常的内存 ram 大小是多少?(xamarin)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个包含许多活动的应用程序.还有带有图像的列表视图等等.这是来自 apk 的图像.这是一张图片

I'm using an application with many activities inside. also listview with images and so on. Here is an image from apk. Here is an image

第一个问题,这个带红圈的内存是什么类型的?是拉姆吗?还是堆内存?第二个问题每个apk的正常大小是多少.是否比内存大一些安全?第三个问题我的应用程序如果这个内存超过 380mb.在某些情况下,它会使我的 apk 崩溃.错误消息 apk 没有响应.我可以为此做些什么吗?最常见的活动使用带有项目的列表视图:这是我的代码的一部分:我在我的 apk 中使用了很多 sqlite.

First question what kind of memory is this with red circle? Is it Ram? Or heap memory? Second question what is the normal size for each apk.Is it safe bigger than a number of memory? Third question my application if this memory is above 380mb. In some cases it crashes my apk.with error message apk doesnt respond. Is something which i can do for this? Most common activity uses a listview with items inside:Here is part of my code: I'm using very much sqlite in my apk.

var table = db.Query<InventoryPreviewClass>(
    "select * from InventoryPreviewClass where CategoryID =" + 
    Connection.CategoryID + " and InventoryItemName like '%" + 
    etSearchAlwaysOn.Text.ToUpper() + "%'");

mItems = new List<InventoryPreviewClass>();

foreach(var item in table)
{
    mItems.Add(new InventoryPreviewClass() { 
        InventoryItemID = item.InventoryItemID, 
        InventoryItemName = item.InventoryItemName, 
        InventoryItemPrice = item.InventoryItemPrice 
    });
}

MyListViewAdapterInventory adapter = new MyListViewAdapterInventory(this, Resource.Layout.InventoryPreview, mItems);
mlistview.Adapter = adapter;

我也标记了java,原因与此类似

I tag also java cause its similar

推荐答案

第一个问题,这个带红圈的内存是什么类型的?是拉姆吗?还是堆内存?

First question what kind of memory is this with red circle? Is it Ram? Or heap memory?

Working Set :指进程使用的总物理内存 (RAM).有关更多详细信息,您可以参考:什么是私有字节,虚拟字节, 工作集?

Working Set : refers to the total physical memory (RAM) used by the process. For more detail information you could refer to : What is private bytes, virtual bytes, working set?

第二个问题每个apk的正常大小是多少.是否安全大于多个内存?

Second question what is the normal size for each apk. Is it safe bigger than a number of memory?

Android 在 ActiveManager 上提供 MemoryClass获取设备价值的API,详细信息,您可以参考:应用程序可以使用的最大 RAM 量是多少?

Android provide MemoryClass on ActiviyManager API to get the value for your device, for deatail information, you could refer to : What is the maximum amount of RAM an app can use?

如果此内存超过 380mb,则第三次询问我的申请.在某些情况下,它会使我的 apk 崩溃.

Third question my application if this memory is above 380mb. In some cases it crashes my apk.

正如您所说,您的应用程序具有带有图像的 ListView,并且在某些情况下它会使您的 apk 崩溃,当您的应用程序一次加载多个图像时,它会占用大量内存,这通常会导致 OutOfMemoryError,所以我认为您的问题是 OutOfMemoryError.您应该更加关注应用中的堆大小,而不是 Working Set.正如 Android document 所说:

As you said, your application has ListView with images and in some cases it crashes your apk, when you app load many image at one time it will occupy lots of memory, and it usual cause OutOfMemoryError, so I think your problem is an OutOfMemoryError. You should pay more attention to the heap size in your app instead of the Working Set. As the Android document said :

为了允许多个运行进程,Android 对分配给每个应用的堆大小设置了硬性限制.确切的堆大小限制因设备的总体可用 RAM 量而异,具体取决于设备的总内存量.如果您的应用已达到堆容量并尝试分配更多内存,系统将抛出 OutOfMemoryError.

To allow multiple running processes, Android sets a hard limit on the heap size alloted for each app. The exact heap size limit varies between devices based on how much RAM the device has available overall. If your app has reached the heap capacity and tries to allocate more memory, the system throws an OutOfMemoryError.

由于我们不知道您是如何将图片加载到列表视图中的,这里有一些建议:

Since we don't know how did you load images to your listview, here are some suggestion :

  1. 建议实现图片缓存,但无需重新发明轮子,而是专注于应用程序的核心逻辑.只需使用已知且可靠的 Cache & 框架即可获取图像,例如 Picasso滑翔.然后您可以使用它在 listview 中加载图像,如下所示:

  1. It is recommend to implement image cache, but there is no need to reinvent the wheel, focus on the core logic of your app instead. Just use a known and solid framework for Cache & Fetching images, like Picasso or Glide. Then you can use it to load image in your listview like this:

Picasso.With(context).Load(imageUrl).Into(imageView);

    1. 尝试实现 View Holder Pattern 以增加性能 ListViews.Xamrin.Android 示例 此处.
    1. Try to implement View Holder Pattern to increases the performance ListViews. Xamrin.Android example here.

    1. 确保您的应用程序中没有内存泄漏.

  • 这篇关于正常的内存 ram 大小是多少?(xamarin)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆