Max Memory Usage on Watchos 2

Max memory usage on watchOS 2?

Memory usage for WatchKit Application and WatchKit extension is not documented yet . For more detail visit this technical Q&A forum .

Approaching Size Limit - The size of watch application (50MB limit is headache.)

You can definitely save space by only including resources in either the watch app or the watch extension, not both. For resources used in your storyboard or referenced by name in WatchKit methods, like WKInterfaceImage’s setImageNamed(_:) method, you should store them in the watch app itself. For any resources loaded in code by path or with UIImage methods like init?(named:), you’ll want to put them in your WatchKit Extension.

How much memory can one iOS app use?

I wrote a test app that measures how much memory an app can allocate before it's killed. Here are the numbers:

  • iPhone 5s (iOS 10, debug mode, 1GB memory): 600MB can be allocated
  • iPad Air 2 (iOS 11.4, 2GB memory): 1.3GB can be allocated
  • iPhone X (iOS 11.4, 3GB memory): 1.2GB can be allocated
  • iPhone 7 Plus (iOS 12.1, 3GB memory): 1.8GB can be allocated
  • iPad 13-inch (iOS 11.4, 4GB memory): 3GB can be allocated

It's interesting that I never got a memory warning.

Here's the code if you want to run the test yourself:

import UIKit

let sizeInMb = 100

class Wrapper {
var array = [UInt8](repeating: 0, count: sizeInMb * 1048576) // 100 MB
}

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)

var i = 0

sleep(5) // So that you can see how much memory it consumes before any allocations.

while true {
let w = Wrapper()
Unmanaged<Wrapper>.passRetained(w)
i += 1
print("\(i * sizeInMb) MB allocated")
sleep(1) // Give the OS a chance to kill other processes.
}

return true
}

func applicationDidReceiveMemoryWarning(_ application: UIApplication) {
print("Memory warning!")
}
}

This does not work on the simulator. Anything regarding performance should be tested on device.

How big can the payload be when sending data via WatchConnectivity?

According to the private symbols WCPayloadSizeLimitApplicationContext, WCPayloadSizeLimitMessage, WCPayloadSizeLimitUserInfo, the limits (as of iOS 9.0.2) are:

  • 65,536 bytes (65.5 KB) for a message
  • 65,536 bytes (65.5 KB) for a user info
  • 262,144 bytes (262.1 KB) for an application context

I don't know why Apple wouldn't document this, other than the fact that it can be difficult when sending dictionaries through WatchConnectivity to determine exactly how large they are. Certainly the acceptable sizes may change over time.

I couldn't find (and haven't personally observed) any maximum size limit when sending files, though I've noticed that it seems to get unreliable when you send large files (hundreds of MBs).

Data Persistent WatchOS 4.0

UserDefaults is available as of watchOS 2 (for storing lightweight data like settings). Core Data is also available.

Reducing peak memory consumption

I think your problem is that you are doing all the snapshots in the same context (the context the for loop is in). I believe the memory is not being released until the context ends, which is when the graph goes down.

I would suggest you reduce the scope of the context, so instead of using a for loop to draw all frames you would keep track of the progress with some iVars and draw just one frame; whenever you finish rendering the frame, you can call the function again with a dispatch_after and modify the variables. Even if the delay is 0, it will allow the context to end and clean up the memory that is no longer being used.

PS. When I mean context I don't mean a graphics context, I mean a certain scope in your code.

WatchOS 2 best practice for storing/retrieving data

It depends on how much data you are storing. NSUserDefaults has a limit on how much you can store in it. I am using CoreDate in my watchkit app and performance has been great. I would recommend if you are storing a small amount of data then NSUserDefaults would be fine, otherwise look into CoreData.

Where to find Taptic feedback API documentation or capabilities for watchOS 2?

You can find the Apple API documentations for the haptic feedback here:

https://developer.apple.com/documentation/watchkit/wkinterfacedevice

You will find a function named

- playHaptic:

So you need to call this function to play the related haptic. This can be done with the following code:

Swift:

WKInterfaceDevice.currentDevice().playHaptic(<#WKHapticType#>)

Objective-C:

[[WKInterfaceDevice currentDevice] playHaptic:<#WKHapticType#>]

Be aware though, for now these feedbacks are unavailable to test on the simulator (because these haptic feedbacks are produced by the new Taptic Engine which is not accessible from any other device than a real Apple Watch), but you can test it on a real device (with watchOS 2 beta installed) if you have one.

These are the types of haptic you can play:

   WKHapticType.Notification,
WKHapticType.DirectionUp,
WKHapticType.DirectionDown,
WKHapticType.Success,
WKHapticType.Failure,
WKHapticType.Retry,
WKHapticType.Start,
WKHapticType.Stop,
WKHapticType.Click

Is there any limit in storing values in NSUserDefaults?

As long as there's enough space on the iPhone/iPad, you can store NSUserDefault values. All those values is stored into a .plist file, and this file is very small, most of the time under 1 kb (unless you store a lot of data).



Related Topics



Leave a reply



Submit