Apple iOS, compared with Windows Phone 7, in terms of system, memory, CPU processing, and background program operations, is more detailed.

by xue94fwsh on 2012-02-28 14:05:16

Multitasking and Memory Management in iOS

Many people worry about whether their available memory is 350MB or 380MB, going to great lengths to optimize and free up a little more memory. However, the task management and memory management in iOS are quite different from Windows. Many people tend to view iOS through the lens of Windows.

In Windows, the more windows you open, the slower the system becomes. Why? Because all the windows are running simultaneously, consuming CPU resources and occupying memory. If the available memory is insufficient, the system will use the hard drive as virtual memory, causing frequent disk read/write operations that not only consume more power but also slow down the system due to the relatively slower speed of hard drives.

iOS, on the other hand, operates differently. Except for a few applications like music players that can run in the background, most apps are suspended when they are sent to the background. For example, in Need for Speed, once it's moved to the background, the engine roar stops. When switching back, you have to press "Continue" to resume the game. Letting such apps continue running in the background would only waste battery life without any practical benefit. You wouldn't want the race cars to keep crashing around while the app is in the background, right?

Since these apps are suspended in the background, they do not consume CPU resources and thus do not drain the battery.

Even though these apps are suspended, don't they still occupy memory? Does using more memory slow down the system or increase power consumption?

The answer is: No.

iOS does not provide virtual memory for IPA files. If the foreground application requires more memory, iOS will directly release the memory used by background applications rather than using the hard drive as virtual memory (which would increase power consumption). Releasing memory simply involves changing the status of a memory block from "occupied" to "free", discarding the content without swapping it to flash memory, which is much faster.

This shows that our experience with Windows does not apply to iOS.

When deciding which background application's memory to release, there are considerations. Some background applications may have serious consequences if released, such as game applications. Once released, the game ends, and switching back means starting over, losing progress. Other applications, however, are less critical. For instance, an e-book reader can retain just a bookmark after releasing memory, allowing it to reload content upon returning. Similarly, Safari browser can reload pages after releasing memory, without significant consequences.

iOS prioritizes releasing memory from applications that are less sensitive to memory usage.

For applications that have been switched to the background, neither consuming CPU nor having their memory released, they are essentially terminated. Such background applications cannot possibly consume power. Most of the tasks shown when double-clicking HOME fall into this category.

In conclusion, iOS allows users to open applications freely without deliberately closing them. In fact, iOS applications lack an explicit exit function, leading some users to complain about the lack of user-friendliness in Apple's design. To close an application, one must double-click HOME, long-press the icon until it wiggles, then press the cross. As explained earlier, iOS applications do not need to be manually closed.

Apple's multitasking design aims to make users forget about multitasking altogether, similar to the single-tasking nature of iOS 3.x. Users can run whichever application they want and return to the home screen when done, regardless of how many applications are open in the background, without slowing down the foreground application (since background apps are suspended and do not consume CPU).

This concept is unimaginable for Windows but has been achieved by Apple. It’s not that Windows is incapable; rather, Windows is designed for comprehensive multitasking to handle various workloads, whereas iOS is a mobile operating system with different priorities.

Some people question whether full memory load consumes more power than an empty one, believing that an empty memory saves power while a full one increases consumption.

This belief is incorrect.

The concepts of "empty" and "full" refer to the operating system, but for memory chips, they only see 0s and 1s. Even idle memory units contain 0s and 1s that must be preserved. An iPhone 4 with 512MB of memory requires continuous power to maintain all 512MB data once turned on. The operating system cannot selectively cut off power to idle memory units to save energy.

Using a computer as an example, both installed RAM sticks are powered on at startup. The motherboard does not cut power to one stick because of available memory, nor does it re-power it when more memory is needed.

The belief that full memory increases power consumption stems from Windows thinking. In Windows, when memory is full, the system uses the hard drive as virtual memory, increasing power consumption and slowing down performance. In iOS, instead of using the hard drive as virtual memory, iOS releases some background application memory until sufficient memory is available.

Thus, for iOS, whether memory is full or empty makes no difference in power consumption. Since memory release in iOS discards content without saving it to disk (unlike Windows), neither full nor empty memory affects speed.

Some people argue that turning off background processes significantly reduces power consumption.

Regarding this point:

Some forum users turn off all background processes, notifications, and even enable airplane mode, yet overnight standby results in less than 10% battery loss, leaving them puzzled. Others, who know nothing and do nothing, enjoy 100% battery retention overnight.

Power consumption varies from person to person and cannot be generalized.

Personally, with only 2G signal enabled, notifications on, and a few large games left in the background, I lose only 1% overnight.

In reality, when switching back to background games, they are always paused and require pressing the Resume button on the screen to continue. This clearly indicates that games are paused in the background. A completely paused background task continuing to consume power would reflect poorly on Apple's system designers.

For example, in Plants vs Zombies, switching to the background and then back shows "Game Paused". Only after resuming does the game continue. All native background-supported games operate similarly.

The advantage of this multitasking management mechanism is that it does not slow down system performance, maintaining smooth operation even with many applications open. The disadvantage is that certain applications like QQ cannot truly run in the background (hence the need for push notifications), and download tasks pause. However, powerful background software like Backgrounder exists for iPhones. It's unclear if similar software exists for WP7. Users accustomed to WP7 or iPhones find that true background running isn't necessary. Properly implemented QQ push notifications achieve similar functionality. Applications supporting Mango background features can pause when switched away and resume upon return.

WP7 limits five background applications due to the 256MB system memory, where each application's maximum available memory is 90MB. Current devices with 512MB memory allow individual applications up to 90+256MB, approximately enough to run four applications simultaneously. Considering general applications do not always use the full 90MB, running five applications is reasonable.

What is referred to as "no impact" is a general statement. The principle is that new applications request memory, and if insufficient, previous programs' memory is automatically cleared. Although automatic clearing occurs, it is a system judgment process.

In practice, sometimes differences can be felt, especially when opening a large application, which might crash before reopening successfully.

Push notifications can be understood as text messages sent by your carrier, theoretically instant.

A representative example is WP7's built-in Messenger integrated into SMS, which can stay online 24/7 without noticeable power consumption changes. Standby remains two days, regardless of offline status, showing others that you're always online, receiving messages instantly like SMS.

Push notifications aren’t reliant on software on the phone constantly refreshing data every 30 seconds, minute, or two minutes, which would drain the battery and cause delays.

WP7's Messenger stays online 24/7 with no noticeable power consumption change, maintaining two-day standby.

Push notifications should theoretically be instant, though not as immediate as socket-based long connections due to multiple potential delay points.

QQ's push notification delays include Tencent server message processing, connection to Microsoft servers, and final delivery via network connections. Improvements in these areas have made newer versions of QQ more efficient.

Microsoft's own Messenger has fewer uncontrollable factors, better controlling latency.

Foreign software achieves stable push notifications, with Microsoft's own Messenger being even more reliable. QQ needs improvement in addressing network latency issues, similar to accessing live services or experiencing store glitches, due to Microsoft not hosting servers domestically. This increases uncontrollable factors in push notifications.

Except for BlackBerry's push notifications and Find My Phone feature, others, including iPhone, WP, and Android, are not true push notifications but rely on pseudo-long connections or periodic data retrieval.

BlackBerry has a specific SMS-like sending protocol supported by carriers, while others use client-initiated polling. Unified Push servers reduce the number of connections, conserving power. Each device has a unique ID and certificate for secure data retrieval.

(Note: Maintaining data in RAM consumes power. Each bit in RAM requires continuous charging to remain as "1", otherwise leakage would lower its voltage.)

Remember, too many cars create traffic jams! Properly managing two lanes suffices; eight lanes are unnecessary.

Theoretically, memory voltage remains constant, so data exchange does not increase power consumption. Unlike hard drives, which consume more power during seek operations, CPUs adjust frequency based on computational load. Programs use memory primarily to execute data, with memory's main function being pre-caching and fast data exchange. Fundamentally, software reads data from storage cards or flash chips, akin to seek operations, requiring CPU resources for preprocessing.

Regardless of background mechanisms, any background operation consumes resources. System optimization ensures efficient resource allocation, analogous to managing two lanes effectively to allow ten cars versus five cars passing in the same time frame. Ultimately, the system integrates hardware resources, distributing and scheduling them efficiently.

Windows' multitasking is designed for comprehensive work, with different architectural and design philosophies. Compatibility refers more to hardware support, ensuring software runs on more complex hardware configurations without conflicts, achieving balanced efficiency. Mac OS architecture is well-known, with its CPU architecture historically tailored for specific hardware. Thus, Mac OS can only compare with Windows. iOS compares with WM and WP7. iOS differs fundamentally from previous WM versions and is incomparable with Windows. Personally, I believe iOS's background mechanism differs from WP7 and may be less efficient. iOS merely tags resources required by backgrounded applications for quick termination and release. This is akin to deleting files into the recycle bin, easily restorable. These deleted files occupy space and resources.

In contrast, WP7's tombstone mechanism works by terminating running tasks, creating a snapshot of necessary data, logically deleting it, and freeing resources immediately. Data remains physically on the disk unless overwritten, allowing recovery. When needed, programs restore processes quickly based on recorded data. This mechanism ensures minimal resource usage when not needed, and efficient restoration when required, focusing on resurrection efficiency and data integrity verification.

Some might wonder if this approach is more resource-intensive. Those familiar with disk storage principles or RAID understand that data consists of 0s and 1s, with RAID1 or 5 adding checksums during read/write operations to recover data upon disk failure. The original program data file remains intact, requiring no complete record or recovery, only recording necessary runtime data. Restoration doesn't require extensive effort. On iOS, applications like QQ maintain network connection validity, prioritizing over system termination thresholds. Applications needing frequent memory refreshes and disk data modifications, like QQ, show less tolerance on WP7. WP7 terminates all backgrounded applications indiscriminately, packing and burying them, regardless of priority. Microsoft's limit of five allowed background applications likely serves internal convenience, potentially enabling future designated applications to bypass restrictions.

The tombstone mechanism is a rule in Microsoft's Windows Phone 7 operating system. Simply put, when a task is interrupted (e.g., an incoming call), the system records the current application state, halts the program, and restores it based on the recorded data when needed.

Key aspects:

- Microsoft initially did not terminate background processes entirely in early WP7 versions but paused them, causing stack confusion and API/event triggering issues.

- Fully implementing the tombstone mechanism impacts certain functionalities, like SMS, instant messaging, and weather updates, necessitating push notification service APIs for real-time updates.

Through this mechanism, Microsoft ensures efficient multitasking while preserving battery life and consistent user experiences.