Hi Mark, Great article! Thank you so much! Just want to point out something that you mentioned at 7:20. Outlets always are weak by default because the ViewController holds a strong reference to its containerView. If the outlet is strong, the containerView will hold a strong reference to that outlet. So that we have ViewController and containerView will together hold the outlet, which will make the retain cycle. Hope this helps ^^ (sorry for my bad english)
A little late comment here but... Mark, your lessons are crystal clear. I've known and been subscribed to your channel for quite a while now, and everytime something's unclear, I come back to these high quality videos. Once I find myself in a better financial situation (currently bootstrapping my startup) I'll surely support you through Patreon.
Haha! At 1 minute, that is the same face I make when I get mental block while developing something. Amazing video as always and I have been using closures all this time unaware of the idea that they can cause memory leaks. I'll take note of this, thanks!
Ha ha, yes, Mark! I was going to cut that out but decided to leave it in at the last minute to seem more human. Ha ha. Thanks and I'm glad you liked the video!
it would be great if you also teach us about concurrency and RxSwift . since for me personally i don't really grasp those topic. Thank you very much Mark :D
That's awesome, Agung! This is a tough topic for any developer to grasp. It was especially tough for me to break this knowledge down into simple parts that could be taught in a way that made sense. So I'm really glad you appreciate it and more importantly, understand it. That was my goal for all of you. To present in a way that EVERYONE could understand easily.
Nice Job with this Memory Series! Could you stay in this topic and show how to fix the problem with Malloc leaks and Zombies object? It would be great!
hi bro , thanks bro you really helped me to retrive memory issues . I really liked your tutorials thanks you bro please upload thease type of videos with latest updates
Thanks For the Video ... but I suggest to you plz make Video in How to Use OOPS Concept in RealTime in Swift or while developing Application..That is more important for everyone.
Excellent question, Mengyi! The answer is: You totally can! Yes, when looking at the image after this point, where I show the memory graph, you can break any one of those strong references to fix the retain cycle. In the previous video (th-cam.com/video/1LnipXiSrSM/w-d-xo.html) I talked about the 2-Step method of fixing a retain cycle. It's up to the developer to determine who the parent and child classes are. So in this video, I was making the popup the parent and the onSave the child. But you could totally make the ViewController the parent and the popup the child. Both will work. The main thing is you need to create a break somewhere in the retain cycle between the 3 reference types.
Firstly I thanks you for your wonderful video , but I've a doubt ViewController class have Weak reference to its dateLabel property , but in your explanation its stated as Strong reference.
thanx Mr. Mark, for this great video, I have two questions after watched this video 2 times: first: will always be a retain cycle if I put an outside variable/property inside the closure ? and second : sometimes I am not very sure I got a retain cycle or not, can I use [weak self ] capture list anyway in all my closure ? just for sure to remove the potential hazard , will it cost problem later on? thanks very much
Steven Gao, there will never be a retain cycle of the variable/parameter being captured is a value type (see video #1). If it's a reference type it really depends what the code looks like. You can always use [weak self] in a closure with no noticeable performance difference. There is a tiny overhead but your users will most likely never even notice because it's so fast.
Forwarder might be something along "responder chain". But as for "partial apply" is a concept connected with curring. For example you have block that takes two ints as arguments but at the moment you have only one value available. So what you can do is to create a block that will take this one argument and returns another block that expects the second. Because all variables are captured in the most inner scope then there you can complete your computation :) In this context I'm guessing that the "hidden" argument of "self" is passed in :) You can check this playground: iswift.org/playground?uonej7&v=4
Yeah, that's a good point. There's no circular reference, right? And I've done tests with this too and found that a view controller will still get released from memory even if you don't use [weak self] when doing animations.
Mark I have a issue on my project and donot understand the error can you tell me this: LOG SocketIOClient{/swift}: Handling event: error with data: ["Tried emitting newMessage when not connected"]
according to docs retain cycle is only created if a class property refer to a closure (ref: docs.swift.org/swift-book/LanguageGuide/AutomaticReferenceCounting.html ). And in your example you showed UIView.animate() closure which i think wouldnt create retain cycle. If i m wrong please clear me.
hi. so doing [weak label = self.myLabel! ] and the rest. the reference count is 1. in this example it is not necessary o possible to set label or vc to nil . i guesS xD . . great tutorials . i like to learn theory. i helps m understand why im doing what im doing :D
Hi Anurag. Intruments can be weird sometimes as different versions of Xcode and Simulators come out. I have noticed the same thing. One time I run the app, no leaks. I make NO changes. I run it again, it finds a leak. I really hate this kind of inconsistency with Apple's Instrument tools. I wish they were better too. ☹️
Wow! Just wow! If i get a chance to visit US i will definitely visit you sir! Is "MARK: - " in swift is your name ?? Hahaha:) Now if i do work with closure it will definitely reminds me of you! and you'd be like no bruh not this way! Haha . I still have to watch this series on repeat mode. Thank you for this amazing knowledge.
Dude, like, this is mind blowing how you explain it and how logical it is.
Thank you, I try to make it as easy as possible. 😀
Thanks for explaining in such simple details .
Very helpful
You're welcome, Neyaz!
This is more than 2 yrs old but still better than most, if not all, tutorial videos I encountered about this topic. You're really good at this!
Thank you so much, Karla! 😊
@@bigmtnstudio oh, no. Thank YOU for sharing your knowledge and making these concepts easier for us to grasp!
You are by far the best channel producing content about iOS. I wish you would continue to share such an amaziiing videos
Honestly, the best Swift videos on TH-cam are from this guy!
Ha ha, thanks man!
Hi Mark, Great article! Thank you so much! Just want to point out something that you mentioned at 7:20. Outlets always are weak by default because the ViewController holds a strong reference to its containerView. If the outlet is strong, the containerView will hold a strong reference to that outlet. So that we have ViewController and containerView will together hold the outlet, which will make the retain cycle. Hope this helps ^^ (sorry for my bad english)
Oh OK. Well thank you for taking the time to share this with me and other developers that watch the video! 👍🏼
A little late comment here but... Mark, your lessons are crystal clear. I've known and been subscribed to your channel for quite a while now, and everytime something's unclear, I come back to these high quality videos. Once I find myself in a better financial situation (currently bootstrapping my startup) I'll surely support you through Patreon.
Thank you, sir. Glad you like my videos and teaching style!
Awesome....Mark....I watched all videos got whole concept in just 2 hours
Awesome, Rakesh!
This was a great addition to my research relating to memory management!
That's great, Jason. Glad it was helpful!
Great video! Straightforward, simple, easy to understand. Learned a lot just from this video thanks!
Literally watching the ads to support this type of content
Great video! Your teaching matches what I learned from the Stanford iOS class on Closures which taught this: [unowned vc = self] in a closure.
That's awesome! Right on target. 😃
Mmmmmmmhhh damn... this video definitely opened my eyes about closures. I probably created ton of retain cycles in the past without even realizing it
Ha ha ha. Yeah, I'm sure I have too!
Incredibly well-explained, and the video is edited really well. Thank you!
You're welcome, Ryan! Glad you liked it!
Now I know what weak and unowned really mean! Thanks
perfect , I became fan of yours teaching style ..awsome !!
Haha! At 1 minute, that is the same face I make when I get mental block while developing something. Amazing video as always and I have been using closures all this time unaware of the idea that they can cause memory leaks. I'll take note of this, thanks!
Ha ha, yes, Mark! I was going to cut that out but decided to leave it in at the last minute to seem more human. Ha ha. Thanks and I'm glad you liked the video!
thank you so much ! you make it so easy to learn !
You're welcome! I try to teach how I want to learn. And I too like it when others make it easy for me to learn.
It’s amazing how easy you explained things, great content once again. It would be nice a Unit Test video 😃. Thanks again. Subscribed.
Thank you, I'm glad you liked it!
Nice Video sir, it helped me to clear my concepts Thank you, keep growing
hi Mark, Thank you very much for sharing knowledge. I finally UNDERSTAND this topic, you made it really really really easy
it would be great if you also teach us about concurrency and RxSwift . since for me personally i don't really grasp those topic. Thank you very much Mark :D
That's awesome, Agung! This is a tough topic for any developer to grasp. It was especially tough for me to break this knowledge down into simple parts that could be taught in a way that made sense. So I'm really glad you appreciate it and more importantly, understand it. That was my goal for all of you. To present in a way that EVERYONE could understand easily.
Bro, Truly appreciate the effort that you are putting in to these videos. Great work! Thank you!
Thanks! I'm glad you're liking them. 😃
Best video, I'll buy your course :)
Awesome!
Very clear tutorial, thank you so much, Mark 💙
You're welcome, Thanh! Glad you enjoyed it. 😃
The best ever describe memory leaks, Thank you
Thank you, Ahmad. I'm glad you liked it. 😃
awesome video again .. looking fwd to the next episode. 👏 👏
Thanks, Ahmed. I'm almost done with the outline and the slides. Should be recording by tomorrow.
The content is at the top level! Thank you!
No problem. Yuri!
Great tutorial , now I think I will find more than 99 retain cycles in my code :D
Rami Tech. Ha ha ha. Oh man, well, now you know how to fix them!
Thanks Mark, you are THE BEST :)
Thank you so much! I'm glad you liked it. 😀
Nice Job with this Memory Series! Could you stay in this topic and show how to fix the problem with Malloc leaks and Zombies object? It would be great!
Thanks, Tomasz! I have another video I'm going to do so maybe I can fit this in. Thanks for the suggestion!
Great Video , Thank You Very Much
love the way u were stuck in the intro quite natural :)
Great video. Thanks.
hi bro , thanks bro you really helped me to retrive memory issues . I really liked your tutorials thanks you bro please upload thease type of videos with latest updates
Thank you! I created a series called "Swift Memory Mastery". It is using the latest updates.
Very clear, thanks
Oh good, this topic was a challenge for me to make clear and easy to understand.
Bravo.
Thank you!
Awesome Man. Thanks much
Great Tutorial @Mark, Thanks a ton. Apple must hire you to modify their documentation to make it simpler to understand.
No kidding! If their documentation was open source, I'd definitely be contributing. 😃
@@bigmtnstudio BTW, your videos are so good and I am learning a lot from it and guess what Promoting :D Keep posting the good content.
Thanks For the Video ... but I suggest to you plz make Video in How to Use OOPS Concept in RealTime in Swift or while developing Application..That is more important for everyone.
Thanks, Rushang! I'll make note of your request. Thank you.
Thank you very much for the video! I have a question on 8:15. Why can't we just change the popup to be a weak var? Namely weak var popup?
Excellent question, Mengyi! The answer is: You totally can! Yes, when looking at the image after this point, where I show the memory graph, you can break any one of those strong references to fix the retain cycle. In the previous video (th-cam.com/video/1LnipXiSrSM/w-d-xo.html) I talked about the 2-Step method of fixing a retain cycle. It's up to the developer to determine who the parent and child classes are. So in this video, I was making the popup the parent and the onSave the child. But you could totally make the ViewController the parent and the popup the child. Both will work. The main thing is you need to create a break somewhere in the retain cycle between the 3 reference types.
@@bigmtnstudio Thank you very much, Mark! I just wanted to know that there could be another solution.
Great work sir make video on extension also
Thanks, Zahid!
Firstly I thanks you for your wonderful video , but I've a doubt ViewController class have Weak reference to its dateLabel property , but in your explanation its stated as Strong reference.
Great video, thanks for sharing your knowldege, I will let know all my friends about your channel xD
Thanks, Miguel!
thanx Mr. Mark, for this great video, I have two questions after watched this video 2 times: first: will always be a retain cycle if I put an outside variable/property inside the closure ? and second : sometimes I am not very sure I got a retain cycle or not, can I use [weak self ] capture list anyway in all my closure ? just for sure to remove the potential hazard , will it cost problem later on? thanks very much
Steven Gao, there will never be a retain cycle of the variable/parameter being captured is a value type (see video #1). If it's a reference type it really depends what the code looks like. You can always use [weak self] in a closure with no noticeable performance difference. There is a tiny overhead but your users will most likely never even notice because it's so fast.
Thank you................
You're welcome, sir. ✊️
Please you make video on Swift Properties in deep ?
Thanks very good
Thanks, Hossein!
Forwarder might be something along "responder chain". But as for "partial apply" is a concept connected with curring. For example you have block that takes two ints as arguments but at the moment you have only one value available. So what you can do is to create a block that will take this one argument and returns another block that expects the second. Because all variables are captured in the most inner scope then there you can complete your computation :) In this context I'm guessing that the "hidden" argument of "self" is passed in :)
You can check this playground:
iswift.org/playground?uonej7&v=4
I think UIView animation doesn't make memory leak because the ViewController doesn't reference to it
Yeah, that's a good point. There's no circular reference, right? And I've done tests with this too and found that a view controller will still get released from memory even if you don't use [weak self] when doing animations.
@@bigmtnstudio please fix your video too. Also non-escaping closure that doesn't delay its execution can't create a retain cycle.
Awasome @Mark
Muhammad Ali, thank you! 😊
Mark I have a issue on my project and donot understand the error can you tell me this:
LOG SocketIOClient{/swift}: Handling event: error with data: ["Tried emitting newMessage when not connected"]
@Mark one question here, what will happen if i create IBoutlet as strong, is this going to create a memory leak
according to docs retain cycle is only created if a class property refer to a closure (ref: docs.swift.org/swift-book/LanguageGuide/AutomaticReferenceCounting.html ). And in your example you showed UIView.animate() closure which i think wouldnt create retain cycle. If i m wrong please clear me.
hi. so doing [weak label = self.myLabel! ] and the rest. the reference count is 1. in this example it is not necessary o possible to set label or vc to nil . i guesS xD . . great tutorials . i like to learn theory. i helps m understand why im doing what im doing :D
add lifetimetracker library for dev builds and you will see all the leaks that closure strong references create
u great 🙈🙊🙉.
Thanks, Jackson! Glad you liked the video. 😃 Did you do the whole series or just this one?
Hi, mark, i have a question about if we put (popup.onSave = nill), what will happen to the clouser, does it remains in memory?
No it does not! That is a valid way to remove it.
HI Mark,
I tried to find leaks through instrument for this example but instrument unable to detect leaks.
Thanks and Regards
Anurag Sharma
Hi Anurag. Intruments can be weird sometimes as different versions of Xcode and Simulators come out. I have noticed the same thing. One time I run the app, no leaks. I make NO changes. I run it again, it finds a leak. I really hate this kind of inconsistency with Apple's Instrument tools. I wish they were better too. ☹️
thanks mark , your videos are mind blowing . Its really helpful.
Wow! Just wow! If i get a chance to visit US i will definitely visit you sir!
Is "MARK: - " in swift is your name ?? Hahaha:) Now if i do work with closure it will definitely reminds me of you! and you'd be like no bruh not this way! Haha . I still have to watch this series on repeat mode. Thank you for this amazing knowledge.
Ha ha ha, thanks, Kishan!
Good good !!!!👏👏👏👏😃😃😃
Obrigado, Marcela!
Mark Moeykens thanks😃
DOOD!
Hiya, 10! 😄