retain-cycle

SpriteKit not deallocating all used memory

纵饮孤独 提交于 2020-01-12 03:56:08
问题 I have ready many (if not all) articles on SO and other sites about the disasters of dealing with SpriteKit and memory issues. My problem, as many others have had, is after i leave my SpriteKit scene barely any of the memory added during the scene session is released. I've tried to implement all suggested solutions in the articles i've found, including, but not limited to... 1) Confirm the deinit method is called in the SKScene class. 2) Confirm no strong references to the parent VC in the

Block and retain cycle can't catch it

瘦欲@ 提交于 2020-01-06 19:03:44
问题 I've got an issue with blocks and weak reference, I'm under ARC. I built a class it is a free project that is a kind of easy wrapper around Google Directions API you can download it here:link to the project Im'm using it inside a view controller the problem is that after using it the view controller is not deallocated. I guess that is an issue with this object because if I comment it out or set to nil everything works correctly. I'm not able to understand where is the retain cycle, of course

Block and retain cycle can't catch it

懵懂的女人 提交于 2020-01-06 19:03:07
问题 I've got an issue with blocks and weak reference, I'm under ARC. I built a class it is a free project that is a kind of easy wrapper around Google Directions API you can download it here:link to the project Im'm using it inside a view controller the problem is that after using it the view controller is not deallocated. I guess that is an issue with this object because if I comment it out or set to nil everything works correctly. I'm not able to understand where is the retain cycle, of course

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

Do methods called from within a block need to use weakSelf?

谁都会走 提交于 2020-01-01 19:51:10
问题 If the code inside a block calls a method, will a retain cycle exist if that method references self? In other words, does all code downstream of a block need to use the weakSelf/strongSelf pattern? For example: __weak __typeof__(self) weakSelf = self; Myblock block = ^{ [weakSelf doSomething]; }; . . . - (void)doSomething { self.myProperty = 5; // Is this ok or does it need to use a weakSelf? } 回答1: Retain cycle will be triggered only if you retain self inside the block. Otherwise it will

How to Correctly handle Weak Self in Swift Blocks with Arguments

这一生的挚爱 提交于 2019-12-27 12:10:06
问题 In my TextViewTableViewCell , I have a variable to keep track of a block and a configure method where the block is passed in and assigned. Here is my TextViewTableViewCell class: // // TextViewTableViewCell.swift // import UIKit class TextViewTableViewCell: UITableViewCell, UITextViewDelegate { @IBOutlet var textView : UITextView var onTextViewEditClosure : ((text : String) -> Void)? func configure(#text: String?, onTextEdit : ((text : String) -> Void)) { onTextViewEditClosure = onTextEdit

How to avoid memory leaks with nested objects

落花浮王杯 提交于 2019-12-25 18:26:23
问题 imagine a Swift object A that has a reference to objects B and C, and that object B also has a reference to C as depicted in below: Object A: - Object B - Object C Object B: - Object C Assuming that all the references are strong, will this cause a memory leak? Should the reference to Object C by Object B be a weak one in order to avoid leaks? Thanks! 回答1: In your first example, as long as neither B nor C have strong references back to A, there is no strong reference cycle and thus no memory

Swift: Retain cycle with NSOperation

假如想象 提交于 2019-12-23 12:43:10
问题 In my app I use an image loader class to load images from the web for a collection view. The class keeps track of the download operations and cancels them when the cells for the images are no longer visible in the collection view. This implementation is based on the raywenderlich tutorial for NSOperation: http://www.raywenderlich.com/76341/use-nsoperation-nsoperationqueue-swift. I use NSOperation for downloading an image from the web. I noticed with Instruments that none of the NSoperations

substituting for __weak when not using ARC

╄→гoц情女王★ 提交于 2019-12-21 05:22:14
问题 I have this line of code: __weak NSBlockOperation *weakOperation = operation; which is triggering this compiler error: __weak attribute cannot be specified on automatic variable. Reason for this is I don't have ARC enabled (not ready to make the switch just yet). So from another StackOverFlow question, I was recommended to use: __unsafe_unretained NSBlockOperation *weakOperation = operation; Which makes the error go away, but for the context I'm using it, it's not working (see this question

Swift Memory Management: Storing func in var

断了今生、忘了曾经 提交于 2019-12-21 04:53:25
问题 I'm looking for the best practice for storing functions as variable in other objects. Specifically, I'm looking to avoid retain cycles inherent in capturing self in the function. Coming from objective-c and blocks, I would normally do something like this: __weak id _self = self; iVar.someBlock = ^{ [_self doSomething]; }; Of course, the iVar class would copy the block and store it. No retain cycle exists because I've capture __weak id _self . In Swift, I'm a little less certain, especially