weak-references

Creating views programmatically Strong Vs Weak subviews in controller

心不动则不痛 提交于 2019-12-04 14:42:20
问题 I am writing a small test program using Xcode 5.1.1, for iOS 7.1. I am not using Xib or Storyboard. Everything is done programmatically. In the AppDelegate.m, I create an instance of my TestViewController and set it as the rootViewController of the window. Inside TestViewController.m, I override the "loadView" to create and assign the main view of the controller. TestViewController.h -------------------- @interface TestViewController : UIViewController @property (nonatomic, weak) UILabel

How to keep track of instances of python objects in a reliable way?

自闭症网瘾萝莉.ら 提交于 2019-12-04 12:15:55
问题 I would like to be able to keep track of instances of geometric Point objects in order to know what names are already "taken" when automatically naming a new one. For instance, if Points named "A", "B" and "C" have been created, then the next automatically named Point is named "D". If Point named "D" gets deleted, or its reference gets lost, then name "D" becomes available again. The main attributes of my Point objects are defined as properties and are the quite standard x , y and name .

Objective-C - weak property - getter autoreleases (Automatic Reference Counting)

删除回忆录丶 提交于 2019-12-04 10:16:46
I have a doubt regarding weak property in ARC (auto reference counting) My understanding (correct me if I am wrong): weak property behaves similar to the assign property except that when the instance that the property was pointing to gets destroyed, the ivar is made to point to nil. Question: I just feel that the getter of the weak property retains and autoreleases. Isn't it suppose to behave like getter of the assign property where the getter doesn't retain and autorelease ?(pls refer to the program) Program: I have given below the program with the actual output and my expected output. Note -

weakref list in python

☆樱花仙子☆ 提交于 2019-12-04 08:37:10
问题 I'm in need of a list of weak references that deletes items when they die. Currently the only way I have of doing this is to keep flushing the list (removing dead references manually). I'm aware there's a WeakKeyDictionary and a WeakValueDictionary, but I'm really after a WeakList, is there a way of doing this? Here's an example: import weakref class A(object): def __init__(self): pass class B(object): def __init__(self): self._references = [] def addReference(self, obj): self._references

Get list of active items from ConditionalWeakTable<T>

一个人想着一个人 提交于 2019-12-04 08:33:05
The .NET 4.0 ConditionalWeakTable<T> is effectively a dictionary where the dictionary's keys are weak referenced and can be collected, which is exactly what I need. The problem is that I need to be able to get all live keys from this dictionary, but MSDN states : It does not include all the methods (such as GetEnumerator or Contains) that a dictionary typically has. Is there a possibility to retrieve the live keys or key-value pairs from a ConditionalWeakTable<T> ? I ended up creating my own wrapper: using System; using System.Collections.Generic; using System.Linq; using System.Runtime

“Weak reference”: down to earth explanation needed

北战南征 提交于 2019-12-04 08:20:44
问题 Can someone provide an explanation of a weak reference in Delphi? I noticed that the concept is often mentioned in some library/framework source code I scrutinize. I'm in a limbo and want to have a clear cut understanding of it. 回答1: Instances that reference each other by interface references keep each other alive in a reference count based interface implementation. A weak reference is used to break the "keep each other alive" bear hug. This is done by declaring one reference as a pure

WeakReference Behavior When Object Is Finalized But Not Yet Garbage Collected

﹥>﹥吖頭↗ 提交于 2019-12-04 08:04:12
Here's an academic question about object finalization and collection in C#/.NET. Background reading is section 3.9 of the C# language spec, Automatic Memory Management. When there are no explicit references to an object, it may become garbage collected. It becomes "eligible for destruction". At some point in the future (e.g. if you force garbage collection), the object's destructor will be run. In the destructor, if you save a reference to the object, the object will be finalized, but will not be eligible for collection. This can lead to an object being in a state where it has been finalized,

When and why would I want to declare a local variable as __weak using ARC?

喜你入骨 提交于 2019-12-04 07:57:57
Mike Ash has written this introduction to ARC where he introduces something like: __weak Foo *_weakFoo = [object foo]; Why would I want to do that for a local, temporary variable? __weak is a zeroing reference which will set the _weakFoo pointer automatically to nil as soon as the referenced object gets deallocated. Also, __weak is only available in iOS >= 5. When would I run into trouble when I simply do this?: Foo *_weakFoo = [object foo]; This is always expected to return an object or nil. My guess is this: Foo *_weakFoo = [object foo]; [self doSomethingStupid]; // does something bad so foo

Is there way to check a `unowned` (actually `unowned(safe)`) reference has been deinited?

孤街浪徒 提交于 2019-12-04 06:48:23
Is there any way to check an unowned(safe) Swift reference for "availability"? So, I am looking for a hypothetical function like isReferenceAccessible in this example: func someMethod() { someAsyncOperation(parameters) { [unowned(safe) self] in guard isReferenceAccessible(self) else { return } self.someAnotherMethod() } } Disclaimer: This question not about weak references! I am aware of how strong , unowned and weak references work. And I don't want to use weak references (because it can be slow, and mutable). I know that unowned(safe) references still be allocated even if it is already

Other uses of weak references?

点点圈 提交于 2019-12-04 05:27:22
I know that weak references are a good candidate for memoizing potentially large sets of data, and Wikipedia's article on weak references only lists "keeping track of the current variables being referenced in the application" and the statement "Another use of weak references is in writing a cache". What are some other situations (more specific than just "caching results") where the use of weak references is A Good Idea TM ? In Flex, use weak references to avoid memory leaks . If an event handler is a member of a short-lived instance object, passing the handler as a strong reference to an