weak-references

Crash with iAd only on iOS 7 - weak delegate is bad pointer

孤街醉人 提交于 2020-01-06 14:54:18
问题 I'm getting a strange crash with the iAd error callback. Here is my crash log: Exception Type: EXC_BAD_ACCESS Code: KERN_INVALID_ADDRESS at 0x2281 0com.apple.main-thread Crashed 0 libobjc.A.dylib objc_retain + 17 1 YouDoodle AdView.m line 265 -[AdContainerView requestGAD] 2 iAd -[ADBannerView _forwardErrorToDelegate:] + 254 3 iAd -[ADBannerView serverBannerViewDidFailToReceiveAdWithError:] + 178 4 iAd -[ADAdSpace setServiceAdSpace:] + 472 5 CoreFoundation __CFNOTIFICATIONCENTER_IS_CALLING_OUT

Why Swift disallows weak reference for non-optional type?

巧了我就是萌 提交于 2020-01-04 15:56:08
问题 This is not pure curiosity, there is a feeling that I may misunderstand something about weak references in Swift. Suppose I create a class from a View Controller and pass its reference to the initialiser: class = MyClass(vc: self) Since the storyboard and window already keep a reference to this View Controller, it seems logical for MyClass to have a weak reference to it (for the similar reason all references created within IB are weak by default): class MyClass: NSObject { private weak var

How can the Objective-C runtime know whether a weakly referenced object is still alive?

老子叫甜甜 提交于 2020-01-04 06:50:14
问题 With the advent of ARC, some new functions were made available to allow developers to play around with weakly referenced objects. id objc_loadWeak(id *location) is one of them. This function receives one parameter correspoding to a location in memory where a weak object was stored and returns this object if it is still alive or nil if it were deallocated. It seems that when an object obj is stored as weak in a location location with id objc_storeWeak(id *location, id obj) , obj is put in a

EXC_BAD_ACCESS when using weakSelf in block / blocks

若如初见. 提交于 2020-01-04 05:25:41
问题 I have been struggeling with this issue for a while since i don't think i fully understand the retain cycles. I am totally new to this and i'm trying to learn more about it. I am getting the EXC_BAD_ACCESS message with the following code. I started using the weakSelf because i get 2 warnings about the retain cycle if i just use self.successBLock();. The exact warning is: Capturing 'self' strongly in this block is likely to lead to a retain cycle Maybe i shouldn't even bother using the weak

How to make weak self in MRC?

安稳与你 提交于 2020-01-03 05:24:09
问题 Message *m = [msg retain]; dispatch_queue_t queue = _handle_queue; __block ProtocolDriver* blockSelf = self; dispatch_async(queue, ^{ if (blockSelf.protocol_delegate && [blockSelf.protocol_delegate respondsToSelector:@selector(onReceive:)]) { [blockSelf.protocol_delegate onReceive:m]; } }); I have a MRC objective-c file, which need run some code in block asynchronously. But I thought the blockself is not safe since it is not weak pointer, Should I change it to true weak pointer. @interface

C# language: why WeakReference or Weak Event Pattern?

牧云@^-^@ 提交于 2020-01-03 01:55:12
问题 I'm reading "The C# Language", 4th edition, it talks about WeakReference and Weak Event Pattern : CHRISTIAN NAGEL: Memory leaks often result from wrong usage of events. If client objects attach to events but do not detach from them, and the reference to the client object is no longer used, the client object still cannot be reclaimed by the garbage collector because the reference by the publisher remains. This can be avoided by (1) detaching of events when the client object is no longer used,

How to maintain a weak pointer to a parent in C++?

偶尔善良 提交于 2020-01-02 19:26:08
问题 Is there a standard way of maintaining a weak pointer to a parent (which is created using a shared pointer) in a child object in C++? Essentially, I need to implement something on the lines of the following: Class B; Class A { ... private: B m_b; }; Class B { .... public: void SetParentPtr(const boost::shared_ptr<A>& a) { m_parentPtr = a; } private: boost::weak_ptr<A> m_parentPtr; }; In the above all instances of class B need to hold a weak pointer to their parent (i.e object of class A).

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

假装没事ソ 提交于 2020-01-02 06:57:14
问题 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 { }

ListView Loading Images with AsyncTask

北城以北 提交于 2020-01-01 21:52:30
问题 I have been reading through a lot of answers of questions that are similar to mine, but still having problem fixing my issue. I have a project that is an RSS Reader that loads in images in the background with an AsyncTask class. The program works, except if the user scrolls quickly then the images sometimes do not load in my rows. They never load in the incorrect spot, it just seems like they are skipped if the user scrolls quickly. Also, on start-up, only 2 or 1 of the images in my listview

HashMap with weak values

杀马特。学长 韩版系。学妹 提交于 2020-01-01 07:50:44
问题 I'm implementing a cache for Objects stored persistently. The idea is: Method getObjectFromPersistence(long id); ///Takes about 3 seconds Method getObjectFromCache(long id) //Instantly And have a method: getObject(long id) with the following pseudocode: synchronized(this){ CustomObject result= getObjectFromCache(id) if (result==null){ result=getObjectFromPersistence(id); addToCache(result); } return result; } But I need to allow the CustomObject to be collected by the garbage collector. Until