简体   繁体   English

iOS相当于增加堆大小

[英]iOS equivalent to increasing heap size

iOS apps (for the most part) is written in Objective-C, which is a subset of C, and is therefore a data managed language, unlike Android/Java. iOS应用程序(大多数情况下)是用Objective-C编写的,它是C的子集,因此是一种数据托管语言,与Android / Java不同。

In Android, you have the ability to increase heap size by simply adding this one line in the XML android manifest: 在Android中,您只需在XML android清单中添加以下一行即可增加堆大小:

<application android:largeHeap="true"/>

Is there an iOS version to doing something like this? 是否有iOS版本可以执行此类操作?

Well in iOS you don't have any control over the memory. 在iOS中,您对内存没有任何控制权。

It is all managed by the kernel. 它全部由内核管理。 So you cannot increase the heap size. 因此,您不能增加堆大小。

As pointed out in the comments, memory management has a different notion in iOS. 正如评论中指出的那样,内存管理在iOS中具有不同的概念。

You get as many memory as available but if the app uses to much memory it will be killed by the system. 您将获得尽可能多的可用内存,但是如果应用程序使用了太多内存,它将被系统杀死。

Now that you explained your goal, you shouldn't download large files into memory, this will cause trouble. 既然您已经解释了目标,那么您就不应该将大文件下载到内存中,这会造成麻烦。 Instead you should save it directly to the disk as you get the response. 相反,您应该在获得响应时将其直接保存到磁盘。

Take a look at Apple's " Memory Usage Performance Guidelines " for an explanation of how iOS doesn't manage swap space. 查看Apple的“ 内存使用性能指南 ”,以了解iOS如何不管理交换空间。

Although OS X supports a backing store, iOS does not. 尽管OS X支持后备存储,但iOS不支持。 In iPhone applications, read-only data that is already on the disk (such as code pages) is simply removed from memory and reloaded from disk as needed. 在iPhone应用程序中,只需将已存在于磁盘上的只读数据(例如代码页)从内存中删除,然后根据需要从磁盘中重新加载。 Writable data is never removed from memory by the operating system. 操作系统永远不会从内存中删除可写数据。 Instead, if the amount of free memory drops below a certain threshold, the system asks the running applications to free up memory voluntarily to make room for new data. 相反,如果可用内存量下降到某个阈值以下,则系统会要求正在运行的应用程序自动释放内存以为新数据腾出空间。 Applications that fail to free up enough memory are terminated. 无法释放足够内存的应用程序将终止。

iOS attempts to provide each application with as much of the device's memory as the OS can spare. iOS尝试为每个应用程序提供OS可以保留的尽可能多的设备内存。 However each application is limited to the device's physical memory. 但是,每个应用程序都限于设备的物理内存。 There is no option to allocated larger blocks and expect them to be swapped to disk as needed. 没有选择分配更大的块,并且期望它们可以根据需要交换到磁盘的选项。

Manipulating the heap size in iOS is therefore not a meaningful concept. 因此,在iOS中操作堆大小不是一个有意义的概念。 Each app already has the largest heap the OS can provide. 每个应用程序已经具有操作系统可以提供的最大堆。 Instead apps must attempt to minimize their memory footprint to remain within the available space on the host device. 相反,应用程序必须尝试最小化其内存占用量,以保留在主机设备的可用空间内。 This means purging in-memory caches in response to memory warnings, streaming access to resources on disk (as @CouchDeveloper suggested in a comment), and minimizing the amount of memory used overall. 这意味着响应于内存警告而清除内存中的高速缓存,对磁盘上的资源进行流式访问(如@CouchDeveloper在评论中建议的那样),并最大程度地减少总体上使用的内存量。

As an additional complication iOS attempts to keep memory in use. 作为额外的麻烦,iOS尝试保持内存的使用。 Unused memory is wasted capacity and users may be better served by the OS keeping more applications suspended and in memory rather than terminated. 未使用的内存浪费了容量,操作系统可以将更多应用程序挂起并保留在内存中,而不是终止,从而为用户提供更好的服务。 As a result attempting to measure available free memory does not give a meaningful result. 结果,尝试测量可用的空闲内存不会给出有意义的结果。 As the device runs low on free memory other applications will reduce their use in response to memory warnings or by being terminated completely. 当设备的可用内存不足时,其他应用程序将响应内存警告或完全终止而减少其使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM