You're welcome! This is originally how I was going to teach it, using class instead of AnyObject. But when I was confirming with Swift documentation it was just mentioning AnyObject so I decided to go with that instead. Maybe I should have mentioned both... This is good for others to know, though so I'll pin your comment! Thanks for commenting!
According to Apple, since swift 4 it should be AnyObject check it under the Class-Only Protocols section: "You can limit protocol adoption to class types (and not structures or enumerations) by adding the AnyObject protocol to a protocol’s inheritance list." goo.gl/AYb4Pv
man. your channel is like a gold mine. Thanks for all the effort that you put in these videos. You can't find this type of quality content anywhere else
My second time watching the memory mastery series. So many things clicked and fell into place. Thank you for taking the time to show each solution and running it on the simulator, visually showing what was going on.
you know mark there's a lot of people searching for (retain cycle) and can't find this video you should add #RetainCycle # Swift , you the only one who explain this with details , I can't thank you enough , and some time I feel like you know about swift more than apple do 😂
it always been a tremendou pleasure to watch your video tutorials, delegation and memory leaks have always been a complicated topic for me to learn, and thanks for clear them up for me. just a future suggestion: there is another topic about Generics , something create an universal type which also very confusing but very essential topic, whenever you have time please consider make one for us. thanks
Thanks for these kinds of Tutorial series.I have clear my doubt about Memory management. While creating the app I didn't think about this kind of memory leaks. Now I do. Such a Great tutorial. 👌🏻 👍
Thank you so much @MarkMoeyKens this was a very clear explanation of memory management that can be done in our app. So can you also do a very clear video of TDD process in iOS development??
I'm so glad you enjoyed this series! I normally don't go into these types of subjects but I had to teach something about memory and then it turned into its own series. This was a tough one to teach and keep as simple as possible at the same time. But I think it paid off!
They won't be running out of salt for years lol! Great video, I am guilty with the NotificationCenter haha! This way I can do some testing to make sure I don't create memory leaks, also that deinit is really handy. This is food for the brain, thanks!
Its been two year I get into iOS development. I keep on doing betterment in each project in aspect of Code Structure, OOPs principles etc. But crucial thing memory management, thats what you explained with demo app. I appreciate. Thank you. :)
Hi! Thanks for your videos, they are very helpful! Which macbook model are you using? I want to buy one for ios development but dont know exactly which one I shold go to feel comfortable in developement.
Thank you, Fabin! I'm using a 2014 13" Macbook Pro with a 256 GB SSD and 8 GB RAM. If you're just starting out then I would go with something cheap or used. That's what I did when I was first starting out. Xcode has worked well for me on low resources. Just remember to minimize the number of scenes (view controllers) on your storyboards. 😉You can easily do this with storyboard references (see my storyboard tips videos).
Hey Mark ,you are Awesome ,all your tutorial are easy to understand and easy to implement ,Great Job,I have one doubt i have created a table view in my custom pop ups ,on table view did select i am dismissing the modal controller and passing data through delegate ,but that dismissing action is very slow
Hi Shakti late a bit . Do all your UI stuff and user interaction in main thread ..other things you do in background thread.Always make free your Main thread to take User input as well as update the UI(this advise i got from Core Data Specialist Marcus Zara's one of video)
I've been programming for a while but in other environments/languages. I knew some of the things but I find what happens is when I go to teach something I start to recognize gaps in my knowledge. So I had to study and fill in all those gaps! This was originally going to be one video. But as I started to put together the outline, it just grew and grew into a 4-part series. I actually worked my way backward to find a good starting point to introduce the basics so I could better move into the more advanced topics.
Thank you very much for this tutorial really helped me a lot, I will keep this tricks in mind I faced the same problem before and I fixed it protocol protocolName : class { func funName(); } and declare like this in the class weak var delegate : protocolName?
Mark . I had an interview for junior developer , they asked me about difference between unowned and weak ))) i explained 1 by 1 as you teached but they went further and started to break me :D it is not complete answer and etc . and then wich answer would be complete ??)))
On purpose I did not fix the first memory leak in Notification Center and run the tool you showed us in this memory series that checks for leaks and it didn't find any but It should've. Is the tool not working or I am missing something ?
I notice this happens sometimes too. The tool seems unreliable at times. Sometimes I have to do a Clean on the project (Product > Clean). And other times I've had to restart Xcode! ☹️
Yeah, Brazo, exactly. I even know a former Apple employee and he always uses weak and nothing else. He just does't see the point in taking any chances at all.
When you first set 'observer' object to weak linked - who is holding a strong reference to it? if it is not strong then it should be released as soon as you instantiate it. (Well it will not as memory manager does not react instantly, but if you put it into an auto release block it should). I see it working but I'm having a hard time understanding why it is? Edit: Oh yeah (I'm primary an ObjC guy :) ) - observer is linking to NSNotificationCenter default singleton - singletons internal property is what holding the strong reference. If you created a new normal object - it would go bye bye immediately after creation. weak linking stuff in closures is the only correct way.
Sometimes i use callbacks in a network asynchronous calls, so if i set self as unowned in the closure parameters i get crashes as self gets deallocated when users navigate away from the view controller, is it recommended in that case to set it as weak?
Exactly! What can happen is you reference self in your closure and that code in the closure is actually part of your other class, not self. So self can be deallocated but still be referenced in the other class that owns the closure. So later (after your view controller is deallocated) the code in the closure (part of the second class) can get run and you will get the crash. If this can happen then that's when you'd have to go with weak.
It's not always true, no. If the value on the right side of the = is nil, then it returns false and you don't go into the code in the braces { }. Example: var myOptional: String? = nil if let myValue = myOptional { // False: Code won't be run because myOptional is still nil } myOptional = "I now have a value" if let myValue = myOptional { // True: Code WILL be run because myOptional has a value } Hope that helps!
Yeah, when doing a tutorial I like to give the viewer a visual on what they'll be seeing. Also, another RUclipsr, Brian Vong, covers coding UI extensively. So this provides balance. 😃
I checked your tutorail but worked for a small code for me and I am not able to determine on my app which I made. I get many memory leaks report not able to identify what is the exact issue. Please check this link screenshots of my memory report ibb.co/ji2rAd ibb.co/kMxrAd ibb.co/echDOy
Thank you very much!
You can use instead 'protocolName: AnyObject {}' that's 'protocolName: class {}'
You're welcome! This is originally how I was going to teach it, using class instead of AnyObject. But when I was confirming with Swift documentation it was just mentioning AnyObject so I decided to go with that instead. Maybe I should have mentioned both...
This is good for others to know, though so I'll pin your comment! Thanks for commenting!
Apple's suggestions tend to be quite vague and as seen here around 30:00 that it leads to non-error errors. Go figure!
According to Apple, since swift 4 it should be AnyObject check it under the Class-Only Protocols section: "You can limit protocol adoption to class types (and not structures or enumerations) by adding the AnyObject protocol to a protocol’s inheritance list." goo.gl/AYb4Pv
protocol SomeProtocolName: class {} is now deprecated. We can use AnyObject or NSObjectProtocol.
man. your channel is like a gold mine. Thanks for all the effort that you put in these videos. You can't find this type of quality content anywhere else
Thank you so much! I'm happy you like them. 😃
My second time watching the memory mastery series. So many things clicked and fell into place. Thank you for taking the time to show each solution and running it on the simulator, visually showing what was going on.
You're welcome, Emiko! 😀
you know mark there's a lot of people searching for (retain cycle) and can't find this video you should add #RetainCycle # Swift , you the only one who explain this with details , I can't thank you enough , and some time I feel like you know about swift more than apple do 😂
Thanks, Mazen! I took your suggestion. 😃
No doubt the best explanation of Swift memory management. Good mix of theory and practical tips. Thanks Mark !!!
it always been a tremendou pleasure to watch your video tutorials, delegation and memory leaks have always been a complicated topic for me to learn, and thanks for clear them up for me. just a future suggestion: there is another topic about Generics , something create an universal type which also very confusing but very essential topic, whenever you have time please consider make one for us. thanks
really thank u very much about this , i never have been saw a creative person like u in explaining the part of memory management
Thank you Mark very much, now I can understand ARC, memory leak etc. It was difficult to find great tutorial like these episodes.
That's awesome, Dosbol. Glad I could help!
Thanks for these kinds of Tutorial series.I have clear my doubt about Memory management. While creating the app I didn't think about this kind of memory leaks. Now I do. Such a Great tutorial. 👌🏻 👍
Awesome, Anand! A lot of times I don't catch memory leaks until it's too late...like a year too late. Ha ha ha.
Thank you! Your courses are awesome 👏
THE CONTENT OF THIS TUTORIAL IS PRICELESS! LEARNT SO MUCH FROM THIS... THANKS A LOT!
I had the same problem with Observer (12:00) .and my project used to crash like you shown here . Thanks for this detail explanation Mark.
You are welcome and I'm glad it helped!
Thank you so much @MarkMoeyKens this was a very clear explanation of memory management that can be done in our app. So can you also do a very clear video of TDD process in iOS development??
Thank you very much, learn lot of stuff from this videos.. great work.
You're welcome, Nagaraju. Glad I can help our little iOS development community here on Earth. 😃
hey those who want to dig on memmory leaks. a mine is here. great work sir.
Thanks, Muhammed!
Thanks for providing this great video. This is very helpful for us to understand the retain cycle & memory concept in IOS
You're welcome, Mohd. It's a pleasure to assist my community!
I enjoy your videos, good Sir. Please keep them coming.
Thanks, Pat! I will. 😀
fantastic , marvellous ,fabulous, outstanding , easy , superb, fantabulous,extraordinarily,Wow,Great !
I'm so glad you enjoyed this series! I normally don't go into these types of subjects but I had to teach something about memory and then it turned into its own series. This was a tough one to teach and keep as simple as possible at the same time. But I think it paid off!
Thank you so much for this. Really learned some cool stuff.
You're welcome, Dheeraj! Glad it was useful for you. 😃
They won't be running out of salt for years lol! Great video, I am guilty with the NotificationCenter haha! This way I can do some testing to make sure I don't create memory leaks, also that deinit is really handy. This is food for the brain, thanks!
Ha ha, yeah, totally. I've done the same thing many times too!
By the way, what mouse are you using?
I use the Apple Magic Mouse.
Thanks!
Awesome tutorial
Thanks, Pavan!
Really good. Thank you.
Nabin Rai, I'm glad you liked it!
Love your videos!
Thanks, Kenan, I appreciate you watching them and glad if they help you out! 😀
Thanks for this tutorial series.
You are welcome, Rashesh. It was probably the hardest series I ever created but I think it was worth the time because it's an important subject.
Its been two year I get into iOS development. I keep on doing betterment in each project in aspect of Code Structure, OOPs principles etc. But crucial thing memory management, thats what you explained with demo app. I appreciate. Thank you. :)
Excellent! Thank you
You're welcome!
Hi! Thanks for your videos, they are very helpful! Which macbook model are you using? I want to buy one for ios development but dont know exactly which one I shold go to feel comfortable in developement.
Thank you, Fabin!
I'm using a 2014 13" Macbook Pro with a 256 GB SSD and 8 GB RAM. If you're just starting out then I would go with something cheap or used. That's what I did when I was first starting out. Xcode has worked well for me on low resources. Just remember to minimize the number of scenes (view controllers) on your storyboards. 😉You can easily do this with storyboard references (see my storyboard tips videos).
Thanks for your advice! Maybe I'll choose Air 2017 for starting out. Ye, I've already watched almost all your videos. They're very useful, keep doing!
Wow, I'm impressed! Thanks for watching. 😀
Hey Mark ,you are Awesome ,all your tutorial are easy to understand and easy to implement ,Great Job,I have one doubt
i have created a table view in my custom pop ups ,on table view did select i am dismissing the modal controller and passing data through delegate ,but that dismissing action is very slow
Thanks, Shakti. I try to make them easy as possible. That's how I like to learn.
Do you still have the slow dismissing of your popup?
i just dissmissed it in DispatchQueue in main thread everythings worked
Awesome! That actually makes sense. When I'm doing UI stuff not in the main thread then I see delays.
Thanks Mark ,it really motivates a lot .
Hi Shakti late a bit . Do all your UI stuff and user interaction in main thread ..other things you do in background thread.Always make free your Main thread to take User input as well as update the UI(this advise i got from Core Data Specialist Marcus Zara's one of video)
Actually when you try to using capture list with [weak self] to avoid the optional inside closure you can use guard. Hope it helps
Yeah! Guard is awesome. That's one of the first things I do now.
yo was it hard understanding all this at first? or u been programming for while so it was easy
I've been programming for a while but in other environments/languages. I knew some of the things but I find what happens is when I go to teach something I start to recognize gaps in my knowledge. So I had to study and fill in all those gaps! This was originally going to be one video. But as I started to put together the outline, it just grew and grew into a 4-part series. I actually worked my way backward to find a good starting point to introduce the basics so I could better move into the more advanced topics.
Thank you very much for this tutorial really helped me a lot, I will keep this tricks in mind
I faced the same problem before and I fixed it
protocol protocolName : class {
func funName();
}
and declare like this in the class
weak var delegate : protocolName?
Mark . I had an interview for junior developer , they asked me about difference between unowned and weak ))) i explained 1 by 1 as you teached but they went further and started to break me :D it is not complete answer and etc . and then wich answer would be complete ??)))
I've come back to most of my tutorial apps and added in [unowned self] everywhere I could xD
That's awesome! 😃
how about static class? is that same thing with singleton? using static class inside the closure?
thank you for your videos! i wish i could leave 10k likes
You're welcome! I would love 10k likes! 😃
On purpose I did not fix the first memory leak in Notification Center and run the tool you showed us in this memory series that checks for leaks and it didn't find any but It should've. Is the tool not working or I am missing something ?
I notice this happens sometimes too. The tool seems unreliable at times. Sometimes I have to do a Clean on the project (Product > Clean). And other times I've had to restart Xcode! ☹️
So, dude when I am unsure I take always weak right? Thx
Yeah, Brazo, exactly. I even know a former Apple employee and he always uses weak and nothing else. He just does't see the point in taking any chances at all.
When you first set 'observer' object to weak linked - who is holding a strong reference to it?
if it is not strong then it should be released as soon as you instantiate it. (Well it will not as memory manager does not react instantly, but if you put it into an auto release block it should).
I see it working but I'm having a hard time understanding why it is?
Edit: Oh yeah (I'm primary an ObjC guy :) ) - observer is linking to NSNotificationCenter default singleton - singletons internal property is what holding the strong reference. If you created a new normal object - it would go bye bye immediately after creation. weak linking stuff in closures is the only correct way.
Sometimes i use callbacks in a network asynchronous calls, so if i set self as unowned in the closure parameters i get crashes as self gets deallocated when users navigate away from the view controller, is it recommended in that case to set it as weak?
Exactly! What can happen is you reference self in your closure and that code in the closure is actually part of your other class, not self. So self can be deallocated but still be referenced in the other class that owns the closure. So later (after your view controller is deallocated) the code in the closure (part of the second class) can get run and you will get the crash. If this can happen then that's when you'd have to go with weak.
Dude you write if let observer = observer is that still true? Like 1 : 1? I am a litle bit confused about that! Could you explain me that? Thanks!
It's not always true, no. If the value on the right side of the = is nil, then it returns false and you don't go into the code in the braces { }.
Example:
var myOptional: String? = nil
if let myValue = myOptional {
// False: Code won't be run because myOptional is still nil
}
myOptional = "I now have a value"
if let myValue = myOptional {
// True: Code WILL be run because myOptional has a value
}
Hope that helps!
Really gReat!
Thanks, Mohammad!
Use delegates, deininit, viewwilldisappear
Solved error message
stackoverflow.com/questions/24066304/how-can-i-make-a-weak-protocol-reference-in-pure-swift-without-objc
Yes! Exactly!
almost your videos is belong to Storyboard for creating UI .
Yeah, when doing a tutorial I like to give the viewer a visual on what they'll be seeing. Also, another RUclipsr, Brian Vong, covers coding UI extensively. So this provides balance. 😃
I think I will use tools for UI :D
I checked your tutorail but worked for a small code for me and I am not able to determine on my app which I made. I get many memory leaks report not able to identify what is the exact issue. Please check this link screenshots of my memory report
ibb.co/ji2rAd
ibb.co/kMxrAd
ibb.co/echDOy