English 中文(简体)
引擎盖下面的... 功能薄弱的可变因素是怎么回事?
原标题:What s going on with __weak qualified variables under the hood?

通常使用 weak 引用以避免在应用程序对象图中保留周期。 我理解这部分。 现在我想更进一步,了解它们是如何在引擎盖下工作的。

略微搜索时,我读过,当我使用 修饰符时,该修饰符的相关变量在自动释放池中注册,但这意味着什么?为什么该对象在游泳池中注册?使用的是哪种池?它是主池还是其他特别创建的?

当我使用这个代码时:

id _weak myWeakObj = [[NSObject alloc] init];

编译者给我一个警告,我可以解决:

id _strong myStrongObj =  [[NSObject alloc] init];
id _weak myWeakObj = myStrongObj;

因此,基于上一个问题, myStrongObj 所引用的对象会怎么样? 如果可能的话,我想知道编译器的代码长什么样?

最佳回答

以下是你的朋友:

以及目标C运行时间的来源:

特别要注意:

如果您在第一个链接下查看 objc_initWeak >objc_destroyweak , 并会看到它是如何“在引擎盖下”操作的。 内脏在 weak_register_no_lock 中,用于登记薄弱的参考,在 weak_unregister_no_lock 中则用于解密薄弱的引用。

我将留给你来研究,看看它是如何运作的:-)。

问题回答

暂无回答




相关问题
Windows Mobile 6 Emulator change storage?

How do i change the size of the Windows Mobile 6 Emulator. Its fixed at 32mb. I read this post: Increasing Windows Mobile 5 Emulator Storage But it only helps for the 5.0 version. Isnt there any way ...

CUDA Memory Allocation accessible for both host and device

I m trying to figure out a way to allocate a block of memory that is accessible by both the host (CPU) and device (GPU). Other than using cudaHostAlloc() function to allocate page-locked memory that ...

RAM memory reallocation - Windows and Linux

I am working on a project involving optimizing energy consumption within a system. Part of that project consists in allocating RAM memory based on locality, that is allocating memory segments for a ...

Should I send retain or autorelease before returning objects?

I thought I was doing the right thing here but I get several warnings from the Build and Analyze so now I m not so sure. My assumption is (a) that an object I get from a function (dateFromComponents: ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

doubts regarding Memory management in .net

I m learning about Memory management in C# from the book "Professional C#" The presence of the garbage collector means that you will usually not worry about objects that you no longer need; ...

Objective-C returning alloc d memory in a function == bad?

This is on the iPhone. So what if I have a function like - (SomeObject*)buildObject; Do I need to pass in a variable that I have already alloc d outside like - (void)assignObject(SomeObject** out);...

热门标签