You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS下CoreML/Metal场景App存储占用持续增长问题排查

TensorFlow Lite模型重复加载导致iOS App存储持续增长问题

问题更新

已在苹果开发者论坛得到回复,该问题大概率源于TensorFlow Lite的CoreML delegate实现。

问题描述

每次加载TensorFlow Lite模型时,App的存储占用都会增加,且无法自动清理。以iPhone上的PoseNet TensorFlow Lite模型为例,切换模型时存储增长的情况可查看对应演示视频。另有一款基于Metal或CoreML运行的模型,每次加载会使App存储占用增加约300MB,长期使用后存储占用可达数GB,最终导致设备存储耗尽、App无法启动。曾尝试按照常规iOS缓存清理方法在App启动时清理存储,但未能解决问题。

相关参考

  • SwiftUI Demo APP结合CoreML导致App体积增长问题
  • 加载CoreML模型导致App体积增大的论坛讨论

警告日志线索

每次重新加载模型或关闭App时,都会出现如下警告日志,该日志可能与存储问题相关:

doUnloadModel:options:qos:error:: model=_ANEModel: { modelURL=file:///var/mobile/Containers/Data/Application/B95DFE34-2664-44E6-A76F-8655EF500E5D/tmp/1D6F1D57-6B7B-4810-9DCC-DBA115104D14-9816-000005716C16268D.mlmodelc/ : sourceURL= (null) : key={"isegment":0,"inputs":{"0_62":{"shape":[257,257,1,3,1]}},"outputs":{"110_0":{"shape":[9,9,1,34,1]},"109_0":{"shape":[9,9,1,17,1]},"112_0":{"shape":[9,9,1,32,1]},"111_0":{"shape":[9,9,1,32,1]}}} : identifierSource=0 : cacheURLIdentifier=D57E9D7D928A79F85793927E324F52140B1517B87B8E491CD2C5BACD02351EEE_3FB4BC7D39229579590186066A34502862A58CA73B7B7C276A9AA0F535B53525 : string_id=0x00000000 : program=_ANEProgramForEvaluation: { programHandle=5984711941790 : intermediateBufferHandle=5984712028205 : queueDepth=127 } : state=3 : programHandle=5984711941790 : intermediateBufferHandle=5984712028205 : queueDepth=127 : attr={
    ANEFModelDescription =     {
        ANEFModelInput16KAlignmentArray =         (
        );
        ANEFModelOutput16KAlignmentArray =         (
        );
        ANEFModelProcedures =         (
                        {
                ANEFModelInputSymbolIndexArray =                 (
                    0
                );
                ANEFModelOutputSymbolIndexArray =                 (
                    0,
                    1,
                    2,
                    3
                );
                ANEFModelProcedureID = 0;
            }
        );
        kANEFModelInputSymbolsArrayKey =         (
            "0_62"
        );
        kANEFModelOutputSymbolsArrayKey =         (
            "109_0@output",
            "110_0@output",
            "111_0@output",
            "112_0@output"
        );
        kANEFModelProcedureNameToIDMapKey =         {
            net = 0;
        };
    };
    NetworkStatusList =     (
                {
            LiveInputList =             (
                                {
                    BatchStride = 444096;
                    Batches = 1;
                    Channels = 3;
                    Depth = 1;
                    DepthStride = 444096;
                    Height = 257;
                    Interleave = 1;
                    Name = "0_62";
                    PlaneCount = 3;
                    PlaneStride = 148032;
                    RowStride = 576;
                    Symbol = "0_62";
                    Type = Float16;
                    Width = 257;
                }
            );
            LiveOutputList =             (
                                {
                    BatchStride = 9792;
                    Batches = 1;
                    Channels = 17;
                    Depth = 1;
                    DepthStride = 9792;
                    Height = 9;
                    Interleave = 1;
                    Name = "109_0@output";
                    PlaneCount = 17;
                    PlaneStride = 576;
                    RowStride = 64;
                    Symbol = "109_0@output";
                    Type = Float16;
                    Width = 9;
                },
                                {
                    BatchStride = 19584;
                    Batches = 1;
                    Channels = 34;
                    Depth = 1;
                    DepthStride = 19584;
                    Height = 9;
                    Interleave = 1;
                    Name = "110_0@output";
                    PlaneCount = 34;
                    PlaneStride = 576;
                    RowStride = 64;
                    Symbol = "110_0@output";
                    Type = Float16;
                    Width = 9;
                },
                                {
                    BatchStride = 18432;
                    Batches = 1;
                    Channels = 32;
                    Depth = 1;
                    DepthStride = 18432;
                    Height = 9;
                    Interleave = 1;
                    Name = "111_0@output";
                    PlaneCount = 32;
                    PlaneStride = 576;
                    RowStride = 64;
                    Symbol = "111_0@output";
                    Type = Float16;
                    Width = 9;
                },
                                {
                    BatchStride = 18432;
                    Batches = 1;
                    Channels = 32;
                    Depth = 1;
                    DepthStride = 18432;
                    Height = 9;
                    Interleave = 1;
                    Name = "112_0@output";
                    PlaneCount = 32;
                    PlaneStride = 576;
                    RowStride = 64;
                    Symbol = "112_0@output";
                    Type = Float16;
                    Width = 9;
                }
            );
            Name = net;
        }
    );
} : perfStatsMask=0}  was not loaded by the client.

该警告中的文件路径与Xcode文件检查器中显示的App存储路径一致:
App存储路径截图

内容的提问来源于stack exchange,提问作者leo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 14:24:56