[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Optimize memory usage for your watch face\n\nWear OS improves battery life by tracking memory use. Watch faces using the\nWatch Face Format have memory limits, as per the [Wear OS app quality\nguidelines](/docs/quality-guidelines/wear-app-quality#memory-usage):\n\n- Ambient mode: 10 MB maximum memory use.\n- Interactive mode: 100 MB maximum memory use.\n\n| **Note:** Memory calculations only include bitmaps, fonts, and XML-derived layers.\n\nMemory usage calculation\n------------------------\n\nTo compute memory usage for an image or bitmap font in a watch face using the\nWatch Face Format, the system does the following:\n\n1. Decompress the image or font.\n2. Check if the following optimizations apply:\n - Resizing to better fit the screen\n - Cropping transparent pixels\n - Downsampling to [RGB565](https://en.wikipedia.org/wiki/List_of_monochrome_and_RGB_color_formats#16-bit_RGB_(also_known_as_RGB565)), without loss of fidelity\n\nBased on the resulting bounding box, the size is computed as follows:\n\n- For images and fonts using [RGBA8888](https://en.wikipedia.org/wiki/RGBA_color_model#RGBA8888): 4 x width x height\n- For images and fonts using RGB565: 2 x width x height\n- For images and fonts using the ALPHA_8 bitmap configuration: width x height\n\n| **Note:** If an image has multiple frames (like an animated GIF), the system decompresses each frame. The union of bounding boxes across all frames is the animation's bounding box.\n\n### Interactive mode\n\nTo compute memory usage for interactive mode, the system sums the following\nvalues:\n\n1. The unprocessed size of any [vector fonts](/guide/topics/resources/font-resource)\n2. The estimated usage of the system's default font\n3. The total size of the images and bitmap fonts after cropping, resizing, and reformatting is applied\n\n### Configurations\n\nFor watch faces with [configurations](/training/wearables/wff/user-configuration/user-configurations), the system attempts to calculate the\ntotal size of the watch face resources across different configurations. If the\nnumber of combinations is very large, the system may overestimate how many\nresources are used simultaneously.\n\n### Ambient mode and layers\n\nThe system assumes ambient mode uses up to three full-screen layers, two of\nwhich are static. The layers include:\n\n1. The watch face background. The system treats this as one image, regardless of how many images the background comprises.\n2. Moving parts like hands, digital displays, or dynamic elements.\n3. Remaining elements from the source XML file.\n\nLarge bitmap fonts often use the most memory in ambient mode.\n\nMethods of reducing memory usage\n--------------------------------\n\nUse the following optimizations to reduce memory usage.\n| **Tip:** Use the [Watch Face Format Optimizer](https://github.com/google/watchface/tree/main/tools/wff-optimizer) to automatically apply some optimizations.\n\n### Crop and resize bitmap fonts\n\nCrop your images and [`BitmapFont`](/training/wearables/wff/group/part/text/bitmap-font) objects to match the display size.\n\nWear OS draws watch faces with all images decompressed. A mostly blank\nfull-screen image might consume 3 KB on disk, but 750 KB or more on a\n450-pixel x 450-pixel screen.\n\n### Use consistent bitmap font heights\n\nWhen using a `BitmapFont`, ensure all images for a character have the same\nheight. Likewise, ensure all images for words have the same height.\n\n### Use consistent frame sizes in animations\n\nInstead of moving an image across a watch face, update the elements in the image\nand keep the bounding box position fixed. For example, to animate a circle on\nyour watch face, change its color instead of rolling it.\n\nThis technique shrinks the size of the animation's calculated bounding box.\n\n### Deduplicate images\n\nTo display an image multiple times, include only one image resource and\nreference it multiple times.\n\n### Show progress using arcs\n\nTo simulate a progress bar finishing after 1 minute or 1 hour, don't use 60\nimages. Use an [`Arc`](/training/wearables/wff/group/part/draw/shape/arc) object with an expression controlling its length, as\nshown here: \n\n```xml\n\u003cPartDraw angle=\"0\" width=\"400\" height=\"400\" name=\"ProgressBar\"\n pivotX=\"0.5\" pivotY=\"0.5 x=\"40\" y=\"40\"\u003e\n \u003cArc centerX=\"200\" centerY=\"200\" width=\"400\" height=\"400\"\n startAngle=\"0\" endAngle=\"360\"\u003e\n \u003c!-- Completes a \"progress loop\" every minute. --\u003e\n \u003cTransform target=\"endAngle\"\n value=\"0 + (clamp([SECOND], 0, 60) - 0) * 6\" /\u003e\n \u003cStroke cap=\"ROUND\" color=\"#123456\" thickness=\"10\" /\u003e\n \u003c/Arc\u003e\n\u003c/PartDraw\u003e\n```\n\nTo display a noncontinuous line, for example to achieve a retro digital watch\nstyle look, use a dash property for a [`Stroke`](/training/wearables/wff/group/part/draw/style/stroke) object or a semitransparent\nmask image overlay.\n\n### Place watch hands and complications at the end of the source file\n\nXML nodes are drawn in the order listed in the source XML. By putting watch\nhands and complications at the end, you enable the system to eliminate an entire\nlayer from the ambient mode memory calculation.\n\nEvaluate the memory usage of your watch face\n--------------------------------------------\n\nTo measure the memory usage of your watch face, use the memory footprint\nevaluator tool, available in the [`watchface`](https://github.com/google/watchface) repository on GitHub.\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Arc](/training/wearables/wff/group/part/draw/shape/arc)\n- [Line](/training/wearables/wff/group/part/draw/shape/line)\n- [Rectangle](/training/wearables/wff/group/part/draw/shape/rectangle)"]]