c#,memory-leaks,garbage-collection,weak-references
The MSDN page specifically states that However, in the ConditionalWeakTable class, adding a key/value pair to the table does not ensure that the key will persist, even if it can be reached directly from a value stored in the table ... So it will not cause the kind of leak...
android,garbage-collection,weak-references
In Java, first thing to understand is Garbage Collector reclaims memory from objects which are eligible for garbage collection Question is how is the eligibility defined ? eligibility is decided based upon which kind of references are pointing to that object. Why we need Weak Reference ? If you create...
ios,objective-c,self,weak-references
If we pass self it could lead to a retain cycle under certain conditions (For example some object may have strong reference to the block and self might have strong reference to that object). Passing weak reference into the block guarantees absence of such a retain cycle. But we still...
ios,objective-c,automatic-ref-counting,weak-references,nszombie
Is there a way to test zombies using weak references (I take it that by "zombies" you actually mean dangling pointers...) Not directly, no. The whole point of ARC-weak references is that they prevent dangling pointers. (As you rightly say, they safely replace the potential dangling pointer with nil...
c#,garbage-collection,weak-references
I'm going to attempt an answer at this.. What you're looking for is "I am dead according to the rules of the game" logic. Not "That object is dead because the Garbage Collector says so" logic. To that effect.. you need to flip your thinking to something like this: class...
ios,objective-c,objective-c-blocks,weak-references
Your dispatch_async block is a creating a strong reference. When that block accesses your MyBlockContainer to get its myBlock property, it creates a strong reference to it for the life of that block. If you change your code to this: __weak void (^block)() = self.blockContainer.myBlock; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ block(); });...
ios,objective-c,memory-leaks,objective-c-blocks,weak-references
Run this code through the static analyzer (shift+command+B or choose "Analyze" from the "Product" menu) and it will point out that createCGImage is creating a CGImageRef that you're never releasing. You might want to do something like: CGImageRef imageRef = [context createCGImage:inputImage fromRect:inputImage.extent]; img = [UIImage imageWithCGImage:imageRef]; CFRelease(imageRef); By the...
ios,objective-c,objective-c-blocks,weak-references,retain-cycle
No. Your weakSelf is a weak reference. Weak references do not cause retain cycles. That's the reason for using weak.
ios,objective-c,weak-references,weak-ptr
That check is unnecessary, and is giving you a false sense of security. Here's the problem: __weak typeof(self) weakSelf = self; dispatch_async(dispatch_get_main_queue(), ^{ if (!weakSelf) { return; } // THE LINE OF INTEREST [weakSelf doSomething]; }); At THE LINE OF INTEREST, some other thread might clear the last strong reference...
objective-c,weak-references,objective-c-runtime
No, there is no way to tell if a weak reference has been set to nil because its referent has been deallocated. The weak reference is set to nil by weak_clear_no_lock in objc-weak.mm....
You don't want a WeakReference for this. A WeakReference is used in the case where you are caching large objects in memory (say an image), and you want to indicate it is OK for the Garbage Collector to remove this image if free memory becomes sparse. In this case you...
swift,closures,weak-references
Is it possible to make the closure references weak in my Observable class No. Only class instances can be referred to via weak references in Swift, and a function is not a class instance. (And not only must they be class instances, they must be an Optional wrapping a...
c#,garbage-collection,weak-references
As it turns out, when I got home and compiled it at home, it ran just fine. And when I got back to work, it worked fine there as well. Guess it's just one of those spooky bugs that magically vanish at inexplicable times. I'm just glad to be rid...
The first method is definitely unsafe. There's making the the whole operation atomic. That is, there is nothing preventing the GC from clearing the weakly reachable object after the first get and before the second. The javadoc states Suppose that the garbage collector determines at a certain point in time...
python,inheritance,weak-references
In derived classes you should not put slots that were defined in the base classes. In fact the error says: TypeError: Error when calling the metaclass bases __weakref__ slot disallowed: either we already got one, or __itemsize__ != 0 Simply use: class B(A): __slots__ = ['foo'] This is explained in...
ios,swift,dictionary,weak-references
Sad to say, didSet or willSet observer doesn't get called when weak var raw property value is deallocated. So, you have to use objc_setAssociatedObject in this case: // helper class to notify deallocation class DeallocWatcher { let notify:()->Void init(_ notify:()->Void) { self.notify = notify } deinit { notify() } }...
ios,swift,weak-references,iboutlet,zbar-sdk
It looks like you didn't create a bridging header. Follow the Apple Docs to create one and then import ZBarReaderView.h in the bridging header.
java,weak-references,eclipse-memory-analyzer
Open the histogram view (there is a toolbar button for this, which looks like a bar graph). In the first row of the histogram view where it says "Regex", type WeakReference to filter the view. Find the java.lang.ref.WeakReference line, right-click, and choose "Show Objects By Class" -> "By Outgoing...
objective-c,automatic-ref-counting,weak-references
NSString it is not concrete class, it is interface and factory for many other classes. I've found that value1 is instance of class __NSCFString, but value2 is instance of class NSTaggedPointerString. Class NSTaggedPointerString does not support retain and release (I try to inject some blocks to it methods). If you...
objective-c,swift,uipageviewcontroller,weak-references,self-reference
In Swift you don't need to declare a weakSelf variable outside the closure. Just define your completion block as follows: { [weak self] (finished) -> () in ... } and then use self? inside the block, in case it may be nil. If self cannot be nil, you may need...
objective-c,automatic-ref-counting,weak-references
You would only declare a weak property if it was connected via an IBOutlet or a as a delegate/datasource (references another UIViewController). If you make a weak property, it will be released immediately after instantiating it. However, a weak property connected via an IBOutlet will not release because the view...
objective-c,automatic-ref-counting,objective-c-blocks,weak-references
Consider using the @weakify and @strongify macros, included in Reactive Cocoa or the Extended Objective-C Library. For demonstration of this, see the Avoiding Retain Cycles discussion in Ray Wenderlich's part 2 of 2 discussion about Reactive Cocoa. That article provides the following example: __weak RWSearchFormViewController *bself = self; // Capture...
swift,delegates,weak-references
You generally make class protocols (as defined with class keyword) weak to avoid the risk of a "strong reference cycle" (formerly known as a "retain cycle"). Failure to make the delegate weak doesn't mean that you inherently have a strong reference cycle, but merely that you could have one. With...
No. http://docs.oracle.com/javase/7/docs/api/java/util/WeakHashMap.html Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. Thus care should be taken to ensure that value objects do not strongly refer to their own keys, either directly or indirectly, since that will prevent the keys from being discarded. Note that a...
c#,json,performance,garbage-collection,weak-references
You shouldn't have to do anything special in this case, just consume your objects GC should take care of naturally. A WeakReference is used to reference an object but to not prevent the referenced object from being GC, I don't see any need for a WeakReference here....
android,android-asynctask,weak-references
No, you shouldn't check imageViewReference for null, you should check for null only what it covers - ImageView using the return value of get method.
WeakReference is invariant, since it allows the value to be set, and that wouldn't be valid if it were covariant. To make it covariant you'll need to make a read only wrapper around the reference, and also use an interface. public interface IReadOnlyWeakReference<out T> { T Value { get; }...
java,lambda,javafx,weak-references
Creating a method reference (in this case) is just like creating any other object. So if we replace it with a new expression, example 2 becomes like: private final ListChangeListener<String> listener = new WeakListChangeListener<String>(new Foo()); public void init() { list.addListener(listener); } Whereas example 3 would be: // direct method reference...
ios,objective-c,weak-references
Your cityLabel property can be weak, but you must add it to the view hierarchy before you can assign the property or assign it to a standard (strong reference) variable. What is going on is that your creating a UILabel, then assigning it to a property which assumes no ownership...
You seem to expect id(f) to display the same number as if you just print out f. This is not the case, as shown in this example: >>> f <__main__.Foo object at 0x10929df10> >>> id(f) 4448706320 >>> w <weakref at 0x10928cfc8; to 'Foo' at 0x10929df10> >>> id(w) 4448636872 The other...
python,string,object,weak-references
What you want to do in python can only work with mutable types. If two 'labels' refer to the same mutable object, you can perform actions on one label and it will be reflected when accessing the other since it is the same object. In short, wrap it in a...
ios,swift,automatic-ref-counting,protocols,weak-references
Generics don't do protocol inheritance of their resolving type in the way that you seem to imagine. Your Weak<ClassWithReloadFRC> type is going to be generally useless. For example, you can't make one, let alone load up an array of them. class Thing : ClassWithReloadFRC { func reloadFRC(){} } let weaky...
After thinking about it more, I'd say the code in my question is either pointlessly complicated or needs further refinement, depending on whether or not Foo needs to do something that cannot be done with the application context. If it does, then my getInstance(...) would look similar to what I...
java,garbage-collection,weak-references,weakhashmap
The WeakHashMap will have its keys reclaimed by the garbage collector when they are no longer strongly reachable. Implementation note: The value objects in a WeakHashMap are held by ordinary strong references. Thus care should be taken to ensure that value objects do not strongly refer to their own keys,...
java,android,garbage-collection,android-alertdialog,weak-references
If it is not a copy/paste issue, You problem must be here: mButton = new CustomButton((CustomButton) findViewById(R.id.goButton)); That´s a wrong coding, neither it has to be: mButton = new CustomButton(this); Where this stands for context, or possible without parameter. or it has to be like this: mButton = (CustomButton)findViewById(R.id.goButton); Don´t...
The simple solution to this is that, as far as I can tell, no documentation I can find proves or disproves this, you cannot pickle list/dictionary of dictionary items.
ios,objective-c,iphone,objective-c-blocks,weak-references
You do need a weak reference for the cell completion handler, because you have a reference cycle: self > UITableView > UITableViewCell > self. You do not need to use the __strong qualifier. Variables are strong references by default. You do not need a weak reference for the animation and...
When notify() is called is it possible that the function called through the onNotify() function object will result in registerListener() being called indirectly (or some other code that can add or remove entries in the listeners collection)? If so, then the iter being used in the notify() for loop can...
python,dictionary,weak-references
Why don't you make all of the subdictionaries WeakValueDictionarys? Then, when the only strong reference in dict1 is removed, the weakref in the WeakValueDictionary will cause that entry to be deleted automatically. Example: >>> class A: pass ... >>> import weakref >>> d1 = {} >>> d2 = {'sub': weakref.WeakValueDictionary()}...
c#,.net,events,weak-references
One reason certainly is performance. GC handles (which power all of the "exotic" references such as WeakReference) come with a performance cost. Weak events are slower than "strong" events since they require a GC handle. A strong event is implemented (by default) by an instance field storing a delegate. This...
.net,wpf,prism,weak-references,delegatecommand
The answer was found in the description of CanExecuteChanged. Here it is: /// When subscribing to the <see cref="E:System.Windows.Input.ICommand.CanExecuteChanged"/> event using /// code (not when binding using XAML) will need to keep a hard reference to the event handler. This is to prevent /// garbage collection of the event handler...
since B is already weakly reachable at that time, shouldn't wrB already be cleared at an early time when the weak reachability of B is first detected? This happens at the same time, so there is no earlier time. When a GC starts all objects (e.g. both A and...
objective-c,automatic-ref-counting,swift,weak-references,nspointerarray
Create a generic wrapper as: class Weak<T: AnyObject> { weak var value : T? init (value: T) { self.value = value } } Add instances of this class to your array. class Stuff {} var weakly : [Weak<Stuff>] = [Weak(value: Stuff()), Weak(value: Stuff())] ...
java,weak-references,weakhashmap
Find my the solution while I was writing this question, so just decided to share. Object value = map.get(new Integer(2)); if (map.containsKey(new Integer(2))) { System.gc(); // can happen here System.out.println(value); } else { System.out.println("Key is deleted"); } I have to get value first and only then check for key existence....
swift,closures,grand-central-dispatch,weak-references
You don't have to repeat [weak self] in nested closures in the same way as @weakify or __weak self patterns in Objective-C. [weak self] in Swift automatically creates the same pattern by the compiler, and the weak self is defined by the outer closure is used by the inner closure....
objective-c,automatic-ref-counting,objective-c-blocks,weak-references
Your second idea is actually kind of interesting. typedef void (^NotificationHandler)(Foo* bar, What* ever); @interface NotificationWrapper : NSObject @property (nonatomic, weak) id canary; @property (nonatomic, copy) NotificationHandler handler; @end You can keep these wrapper objects in a simple NSMutableArray, within perhaps a dictionary of notification handlers. Clients can register and...