Memory 4 - Fixing Common Memory Problems: Reusable Popups (iOS, Xcode 9, Swift 4)

  Переглядів 15,443

Mark Moeykens

Mark Moeykens

6 років тому

🌐 www.bigmountainstudio.com
This one video is the end of the Reusable Popups and the Swift Memory Mastery series. Ending both series in one video.
Before I could teach how to fix common memory problems in the Reusable Popups project I first had to teach you how to become masters of Swift Memory!
In this video, you will be learning common mistakes, leaks, and other memory problems with:
* NotificationCenter
* Callbacks
* Delegates
And you will learn how to view or graph out memory problems and how to pick out which way to fix it. There are always multiple solutions.
You will gain a better understanding of:
* Memory leaks
* Retain cycles (circular references, reference cycles)
* Automatic Reference Counting
* Weak and Unowned keywords
Swift Memory Mastery Series: • Swift Memory Mastery
Creating Reusable Popups: • Creating Reusable Popups
FREE SwiftUI PictureBook:
📙 SwiftUI Views: www.bigmountainstudio.com/fre...
COURSES
🎦 This course is hosted on Code with Chris: bigmtn.studio/cwc
SOCIAL
🔷 Twitter: / bigmtnstudio
🟣 Github: github.com/bigmountainstudio
#markmoeykens #bigmountainstudio #iosdevelopment

КОМЕНТАРІ: 90
@yuraoff1383
@yuraoff1383 6 років тому
Thank you very much! You can use instead 'protocolName: AnyObject {}' that's 'protocolName: class {}'
@bigmtnstudio
@bigmtnstudio 6 років тому
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!
@cylenalag
@cylenalag 6 років тому
Apple's suggestions tend to be quite vague and as seen here around 30:00 that it leads to non-error errors. Go figure!
@TanyaBerezovsky
@TanyaBerezovsky 6 років тому
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
@easthastings6919
@easthastings6919 Рік тому
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
@bigmtnstudio
@bigmtnstudio Рік тому
Thank you so much! I'm happy you like them. 😃
@tatianadmitrieva6712
@tatianadmitrieva6712 Рік тому
Thank you! Your courses are awesome 👏
@dhavalnena7386
@dhavalnena7386 4 роки тому
THE CONTENT OF THIS TUTORIAL IS PRICELESS! LEARNT SO MUCH FROM THIS... THANKS A LOT!
@glennadams7047
@glennadams7047 5 років тому
No doubt the best explanation of Swift memory management. Good mix of theory and practical tips. Thanks Mark !!!
@neelamdheeraj
@neelamdheeraj 5 років тому
Thank you so much for this. Really learned some cool stuff.
@bigmtnstudio
@bigmtnstudio 5 років тому
You're welcome, Dheeraj! Glad it was useful for you. 😃
@stevengao8345
@stevengao8345 6 років тому
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
@rasheshbosamiya1482
@rasheshbosamiya1482 6 років тому
Thanks for this tutorial series.
@bigmtnstudio
@bigmtnstudio 6 років тому
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.
@rasheshbosamiya1482
@rasheshbosamiya1482 6 років тому
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. :)
@patbutler5546
@patbutler5546 6 років тому
I enjoy your videos, good Sir. Please keep them coming.
@bigmtnstudio
@bigmtnstudio 6 років тому
Thanks, Pat! I will. 😀
@mohamedsamirsalem5639
@mohamedsamirsalem5639 Рік тому
really thank u very much about this , i never have been saw a creative person like u in explaining the part of memory management
@nagarajukankanala6397
@nagarajukankanala6397 5 років тому
Thank you very much, learn lot of stuff from this videos.. great work.
@bigmtnstudio
@bigmtnstudio 5 років тому
You're welcome, Nagaraju. Glad I can help our little iOS development community here on Earth. 😃
@nvnkumar398
@nvnkumar398 2 роки тому
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??
@dosbol354
@dosbol354 5 років тому
Thank you Mark very much, now I can understand ARC, memory leak etc. It was difficult to find great tutorial like these episodes.
@bigmtnstudio
@bigmtnstudio 5 років тому
That's awesome, Dosbol. Glad I could help!
@farmood100
@farmood100 6 років тому
Thanks for providing this great video. This is very helpful for us to understand the retain cycle & memory concept in IOS
@bigmtnstudio
@bigmtnstudio 6 років тому
You're welcome, Mohd. It's a pleasure to assist my community!
@KMamedoff
@KMamedoff 6 років тому
Love your videos!
@bigmtnstudio
@bigmtnstudio 6 років тому
Thanks, Kenan, I appreciate you watching them and glad if they help you out! 😀
@nabinrai980
@nabinrai980 6 років тому
Really good. Thank you.
@bigmtnstudio
@bigmtnstudio 6 років тому
Nabin Rai, I'm glad you liked it!
@emiclark
@emiclark 4 роки тому
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.
@bigmtnstudio
@bigmtnstudio 4 роки тому
You're welcome, Emiko! 😀
@MarlAtkins
@MarlAtkins 5 років тому
Excellent! Thank you
@bigmtnstudio
@bigmtnstudio 5 років тому
You're welcome!
@sandeep19831000
@sandeep19831000 6 років тому
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.
@bigmtnstudio
@bigmtnstudio 6 років тому
You are welcome and I'm glad it helped!
@anandnimje5750
@anandnimje5750 6 років тому
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. 👌🏻 👍
@bigmtnstudio
@bigmtnstudio 6 років тому
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.
@mazenbaddad7474
@mazenbaddad7474 5 років тому
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 😂
@bigmtnstudio
@bigmtnstudio 5 років тому
Thanks, Mazen! I took your suggestion. 😃
@fawadfarooq
@fawadfarooq 6 років тому
fantastic , marvellous ,fabulous, outstanding , easy , superb, fantabulous,extraordinarily,Wow,Great !
@bigmtnstudio
@bigmtnstudio 6 років тому
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!
@pavanm2024
@pavanm2024 5 років тому
Awesome tutorial
@bigmtnstudio
@bigmtnstudio 5 років тому
Thanks, Pavan!
@muhammedazharudheen2252
@muhammedazharudheen2252 6 років тому
hey those who want to dig on memmory leaks. a mine is here. great work sir.
@bigmtnstudio
@bigmtnstudio 6 років тому
Thanks, Muhammed!
@markarjohnsanantonio1615
@markarjohnsanantonio1615 6 років тому
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!
@bigmtnstudio
@bigmtnstudio 6 років тому
Ha ha, yeah, totally. I've done the same thing many times too!
@markarjohnsanantonio1615
@markarjohnsanantonio1615 6 років тому
By the way, what mouse are you using?
@bigmtnstudio
@bigmtnstudio 6 років тому
I use the Apple Magic Mouse.
@markarjohnsanantonio1615
@markarjohnsanantonio1615 6 років тому
Thanks!
@dmadhukiranraju7458
@dmadhukiranraju7458 5 років тому
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?
@shaktiprakash1723
@shaktiprakash1723 6 років тому
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
@bigmtnstudio
@bigmtnstudio 6 років тому
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?
@shaktiprakash1723
@shaktiprakash1723 6 років тому
i just dissmissed it in DispatchQueue in main thread everythings worked
@bigmtnstudio
@bigmtnstudio 6 років тому
Awesome! That actually makes sense. When I'm doing UI stuff not in the main thread then I see delays.
@shaktiprakash1723
@shaktiprakash1723 6 років тому
Thanks Mark ,it really motivates a lot .
@sandeep19831000
@sandeep19831000 6 років тому
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)
@ErickMartinSusanto
@ErickMartinSusanto 5 років тому
Actually when you try to using capture list with [weak self] to avoid the optional inside closure you can use guard. Hope it helps
@bigmtnstudio
@bigmtnstudio 5 років тому
Yeah! Guard is awesome. That's one of the first things I do now.
@mohammadtahir7931
@mohammadtahir7931 6 років тому
Really gReat!
@bigmtnstudio
@bigmtnstudio 6 років тому
Thanks, Mohammad!
@kell7491
@kell7491 5 років тому
how about static class? is that same thing with singleton? using static class inside the closure?
@gevorgnikoghosyan7252
@gevorgnikoghosyan7252 3 роки тому
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 ??)))
@TheDancing0wind
@TheDancing0wind 6 років тому
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.
@Th-fr3fw
@Th-fr3fw 6 років тому
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.
@bigmtnstudio
@bigmtnstudio 6 років тому
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).
@Th-fr3fw
@Th-fr3fw 6 років тому
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!
@bigmtnstudio
@bigmtnstudio 6 років тому
Wow, I'm impressed! Thanks for watching. 😀
@nickng8069
@nickng8069 5 років тому
I've come back to most of my tutorial apps and added in [unowned self] everywhere I could xD
@bigmtnstudio
@bigmtnstudio 5 років тому
That's awesome! 😃
@glebcherkashyn2357
@glebcherkashyn2357 6 років тому
thank you for your videos! i wish i could leave 10k likes
@bigmtnstudio
@bigmtnstudio 6 років тому
You're welcome! I would love 10k likes! 😃
@MasteRock87
@MasteRock87 6 років тому
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?
@bigmtnstudio
@bigmtnstudio 6 років тому
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.
@viktorkuzmanov3086
@viktorkuzmanov3086 6 років тому
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 ?
@bigmtnstudio
@bigmtnstudio 6 років тому
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! ☹️
@di_nerd_apps
@di_nerd_apps 5 років тому
yo was it hard understanding all this at first? or u been programming for while so it was easy
@bigmtnstudio
@bigmtnstudio 5 років тому
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.
@brazo98
@brazo98 5 років тому
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!
@bigmtnstudio
@bigmtnstudio 5 років тому
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!
@brazo98
@brazo98 5 років тому
So, dude when I am unsure I take always weak right? Thx
@bigmtnstudio
@bigmtnstudio 5 років тому
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.
@SenorQuichotte
@SenorQuichotte 6 років тому
Use delegates, deininit, viewwilldisappear
@BBrezonak
@BBrezonak 6 років тому
Solved error message stackoverflow.com/questions/24066304/how-can-i-make-a-weak-protocol-reference-in-pure-swift-without-objc
@bigmtnstudio
@bigmtnstudio 6 років тому
Yes! Exactly!
@ngoclichtran4876
@ngoclichtran4876 5 років тому
almost your videos is belong to Storyboard for creating UI .
@bigmtnstudio
@bigmtnstudio 5 років тому
Yeah, when doing a tutorial I like to give the viewer a visual on what they'll be seeing. Also, another UKpostsr, Brian Vong, covers coding UI extensively. So this provides balance. 😃
@ngoclichtran4876
@ngoclichtran4876 5 років тому
I think I will use tools for UI :D
@ghousansari6578
@ghousansari6578 6 років тому
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
Memory 2 - Finding and Fixing Memory Leaks (iOS, Xcode 9, Swift 4)
34:31
Mark Moeykens
Переглядів 49 тис.
"Поховали поруч": у Луцьку попрощались із ДВОМА Героями 🕯🥀 #герої #втрати
00:15
Телеканал Конкурент TV - новини Луцька та Волині
Переглядів 283 тис.
😨Новая Война в GTA 5 Online #shorts
00:40
King Dm
Переглядів 1,2 млн
Спектакль для окупантів та ждунів 🤯
00:47
Радіо Байрактар
Переглядів 566 тис.
Анита просто на химии, поэтому такая сильная
00:21
Женя Лизогуб SHORTS
Переглядів 2,8 млн
Memory 1 - Value Types vs Reference Types (iOS, Xcode 9, Swift 4)
11:57
Mark Moeykens
Переглядів 26 тис.
Memory Leaks in iOS: Find, Diagnose, & Fix (2022)
12:44
iOS Academy
Переглядів 44 тис.
Debugging Swift Memory Issues with Xcode and Profiler
25:31
Make School
Переглядів 25 тис.
Weak and Unowned Self Closure Memory Leak Fixes
12:21
Lets Build That App
Переглядів 55 тис.
Machine Learning for Everybody - Full Course
3:53:53
freeCodeCamp.org
Переглядів 5 млн
"Поховали поруч": у Луцьку попрощались із ДВОМА Героями 🕯🥀 #герої #втрати
00:15
Телеканал Конкурент TV - новини Луцька та Волині
Переглядів 283 тис.