weak-references

WeakReferenced object is not garbage collected after calling System.gc()

时光怂恿深爱的人放手 提交于 2019-12-06 15:31:18
I am a fresh new learner of Java. I'm now learning the concept of WeakReference. I came across a problem which probably looks stupid but I just wanna figure out the reason. The problem is: according to Java doc, "Weak reference objects, which do not prevent their referents from being made finalizable, finalized, and then reclaimed." So I did this small test: import java.lang.ref.WeakReference; public class A { public static void main(String[] args) { A a = new A(); WeakReference<A> wr = new WeakReference<>(a); a = null; A a1 = wr.get(); System.out.println(a); System.out.println(a1); try {

HashMap of WeakReferences for passing data between activities

雨燕双飞 提交于 2019-12-06 11:23:17
问题 I am particulary interested in the following suggestion from the official android FAQ. A HashMap of WeakReferences to Objects You can also use a HashMap of WeakReferences to Objects with Long keys. When an activity wants to pass an object to another activity, it simply puts the object in the map and sends the key (which is a unique Long based on a counter or time stamp) to the recipient activity via intent extras. The recipient activity retrieves the object using this key.` I haven't found a

Why WeakReferences in RelayCommand?

为君一笑 提交于 2019-12-06 07:24:18
问题 I recently upgraded from MVVMLight 3 to 4, and noticed that my Commands broke. It turns out that the use of weak references in the new RelayCommand (implemented in version 3.5) were causing a code construct that I am using to fail. I know that there is some argument for weak refs relating to memory leak, I just don't understand it. This fails: private void InitCommand() { Command = new SwitchMainGridCommand<SwitchMainGridToolViewModel>(this).Command; } By fails, I mean that when I go to use

Weak Event Pattern in MonoTouch

风格不统一 提交于 2019-12-06 05:15:06
问题 I used to develop iOS apps using the Objective-C language, and relied on the dealloc method to perform some cleanup/unregister tasks in my application. Now on the MonoTouch (garbage collected) it is not an option anymore. Suppose I have a UIViewController that adds as a subview of it's View property an instance of MyView ( UIView subclass). MyView in turn registers itself to receive some events from another manager/global object so that it knows how to update itself accordingly (e.g.:

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

寵の児 提交于 2019-12-06 04:46:23
问题 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

Why __weak object will be added to autorelease pool?

冷暖自知 提交于 2019-12-06 04:07:30
id __weak obj1 = obj0; equals id __weak obj1 = obj0; id __autoreleasing tmp = obj0; In Pro multithreading and memory management for iOS and OSX . But why the obj1 need to add to the autorelease pool, I think making a weak pointer of an object should not affect its lifetime. { NSObject* sp = [NSObject new]; NSObject* __weak wp = sp; } the above code is translate to: id sp = objc_msgSend(NSObject, "new"); id wp; objc_initWeak(&wp, sp); objc_destroyWeak(&wp); objc_storeStrong(&sp, 0); 1) obj_initWeak merely associate the weak pointer wp with the strong pointer sp to ensure that when the object

Get list of active items from ConditionalWeakTable<T>

醉酒当歌 提交于 2019-12-06 03:57:53
问题 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> ? 回答1: I ended up creating my

Can I create a List<WeakReference<T>>?

匆匆过客 提交于 2019-12-06 01:03:42
I'm trying to create a List of WeakReference s using the 4.5 generic implementation so that I can avoid type checking and casting of the WeakReference target. But, WeakReference<T> doesn't appear to support covariance, so I'm trying to establish a workaround. I'm thinking it should be doable since each T would be of a type in a particular inheritance chain. So, what I'm thinking would be along these lines: public class Animal { } public class Tiger : Animal { } public class Wolf : Animal { } var mylist = new List<WeakReference<Animal>>(); mylist.Add(new WeakReference<Animal>(new Animal()));

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

好久不见. 提交于 2019-12-06 00:34:22
问题 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

Create a weak reference to an object

好久不见. 提交于 2019-12-05 23:49:23
问题 Is it possible in Actionscript 3 to create a weak reference to an object, so that it can be garbage collected. I'm creating some classes to make debugging easier, so I don't want the objects to hang around in memory if they are only referenced here (and of course I don't want to fill the code with callbacks to remove the objects) 回答1: Grant Skinner has written an excellent series of articles on resource management in ActionScript 3, and in the third part of that series he introduces the