OStack程序员社区-中国程序员成长平台

标题: ios - 应用启动时,iOS 是否会将所有系统动态框架加载到内存中? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:12
标题: ios - 应用启动时,iOS 是否会将所有系统动态框架加载到内存中?

根据我的研究,iOS 使用大多数(所有)系统框架作为动态框架。当应用程序启动时,iOS 会加载所有这些吗?或者 iOS 可能会在 iOS 实际需要框架时加载它?

在应用启动时加载它的优势: 在 iOS 调用动态框架中的函数时节省更多时间。

懒加载的好处: 节省更多内存。



Best Answer-推荐答案


Or iOS may load it later when iOS actually need the framework?

Wikipedia page on dynamic linking涵盖了各种流行操作系统的一般概念和一些特定的细节。它(部分)提到了 Darwin ,包括 macOS 和 iOS:

The executables on the macOS and iOS platforms often interact with the dynamic linker during the execution of the process; it is even known that an executable might interact with the dynamic linker, causing it to load more libraries and resolve more symbols, hours after it initially launches.

此外,如果您阅读动态加载程序 dyld 的手册页,您会发现一个名为 DYLD_BIND_AT_LAUNCH 的环境变量,其描述如下:

When this is set, the dynamic linker binds all undefined symbols the program needs at launch time. This includes function symbols that can are normally lazily bound at the time of their first call.

最后一个证据在 Apple 的 Overview of Dynamic Libraries 中。文件,其中部分内容是:

When an app is launched, the OS X kernel loads the app’s code and data into the address space of a new process. The kernel also loads the dynamic loader ( /usr/lib/dyld ) into the process and passes control to it. The dynamic loader then loads the app’s dependent libraries. These are the dynamic libraries the app was linked with. The static linker records the filenames of each of the dependent libraries at the time the app is linked. This filename is known as the dynamic library’s install name.

在下一段中:

The dynamic loader resolves only the undefined external symbols the app actually uses during the launch process. Other symbols remain unresolved until the app uses them.

考虑到这一切,听起来 iOS 可能会在启动应用程序的过程中加载每个动态框架,但实际上会将应用程序中未定义的名称绑定(bind)到框架中的定义,直到它真正实现需要。

关于ios - 应用启动时,iOS 是否会将所有系统动态框架加载到内存中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57750580/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4