菜鸟教程小白 发表于 2022-12-12 15:12:34

ios - 应用启动时,iOS 是否会将所有系统动态框架加载到内存中?


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

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

<p>懒加载的好处:
节省更多内存。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><blockquote>
<p>Or iOS may load it later when iOS actually need the framework?</p>
</blockquote>

<p><a href="https://en.wikipedia.org/wiki/Dynamic_linker" rel="noreferrer noopener nofollow">Wikipedia page on dynamic linking</a>涵盖了各种流行操作系统的一般概念和一些特定的细节。它(部分)提到了 Darwin ,包括 macOS 和 iOS:</p>

<blockquote>
<p><em>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.</em></p>
</blockquote>

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

<blockquote>
<p><em>Whenthisisset,the dynamic linker binds all undefined symbols the program needs at launch time. This includes function symbols that can are normally lazilyboundatthe time of their first call.</em></p>
</blockquote>

<p>最后一个证据在 Apple 的 <a href="https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/OverviewOfDynamicLibraries.html" rel="noreferrer noopener nofollow"><em>Overview of Dynamic Libraries</em></a> 中。文件,其中部分内容是:</p>

<blockquote>
<p><em>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.</em></p>
</blockquote>

<p>在下一段中:</p>

<blockquote>
<p><em>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.</em> </p>
</blockquote>

<p>考虑到这一切,听起来 iOS 可能会在启动应用程序的过程中<em>加载</em>每个动态框架,但实际上会将应用程序中未定义的名称绑定(bind)到框架中的定义,直到它真正实现需要。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 应用启动时,iOS 是否会将所有系统动态框架加载到内存中?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/57750580/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/57750580/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 应用启动时,iOS 是否会将所有系统动态框架加载到内存中?