V. V. G. V. Vv V. v v v v bbbbbbbbBbBbBBbtbtbtbtbtbtbtbtttttbtbBut. . V. V. . V. . B. . . V. V V. V. V. . V. v. ut. But be. Gg. . G. But v. . od. V. V. G g. . . . . . b But v v. V. be. V. V. tbtbt v . V. . G. @@codingwithmitch
So, a memory leak happens when a background threat holds a Context or Activity reference, am I correct? So if I have another normal Java class that holds (requires) a Context or Activity reference but that class does not deal with any background thread, so there would not be any memory leak even though it holds such a reference. Since an object of this class would be gone as soon as the Activity holding that object is gone. Correct me if I was wrong. Because I was so afraid that I manually set the reference to null on each onPause or onDestroy method in an Acticity, in order to make sure the reference would be release :(
So funny to see this video now. "Leak Canary is created by a very well-renowned company called square....". I think you know a lot more about this company now!
Well, to be fair, it's not like your background thread never end. Once it ends, its grabbing to the objects also end, and once the next round of GC kick in and it will be collected.
So how is this not causing a crash ? context is garbage collected before asynctask is completed.. effectively null and mContext points to nothing ? or ... ? could you please explain this?
How do I deal with graphics memory? I have tried several times to get any memory leaks, but I have only gotten a memory leak a few days ago, but I have noticed that the graphics memory doesn't go down any. I haven't been able to find anything as far as managing the graphics memory.
Ok just say I have a context object on a background task but then the associated activity is terminated but it cant be cleaned up, I can understand that the app is then using up more resources than it needs to at this point but when the background task finishes won't the memory be able to be reclaimed by the GC? so what is the big deal if memory is taken up for an extra second or two? Wouldn't this only be a problem on long running background threads?
What if after a while the Garbage collector cleans the memory holding the context object when the activity is destroyed and the weak reference in the AsyncTask is trying to use the context to access a resource for example. Will the App crash? Please help me explain
CodingWithMitch I'm sorry Mitch Tabian. I wanted to follow your channel with the intent of LEARNING stuff and implementing. You're one of the best at what you do. Please don't take the comment negatively. I want to see things work for you. Please try! What if it does
Hi mitch, this is a very good tutorial but i am curious 1. if we use LeakCanary then it always shows a notification when there is memeory leak? if we dont want to show these types of notifications to users and want LeakCanary to run in the background for our mess. Can we customize that too?? 2. Cant we use java Finalize() too??.
I dont have any company experience. I am learning from you guys(you and codeinflow and more) . Can you tell us more how we gonna code in professional build and he we can stop memory leak and give us some tips what we should do while making a professional build.
Doesn't this memory leak stop as soon as AsyncTask is finished? It other words, 5 seconds? You could argue the AsyncTask can be running on for a long time after that. SURE, but then thats the problem: you're running AsyncTask in the background for no good reason. This is a much bigger problem than having reference to the activity since you might be doing some work on that thread and holding resources. TLDR: I believe this video highlights how to program badly with AsyncTask (then fixes it). It doesn't show a real-life case of memory leak.
Thanks for the video, but the leakcanary is not showing any leaks for me. I used your code from the video and I ran my app on emulator and physical device.
@@codingwithmitch yes it points to normal relative layout. But I can't find why because that layout is not static and also not accessing in any background process it always on ui thread.
Wow, just searched in google by recent and this video appeared... I can't use memory profiler in android 3.0 to find memory leaks.. It is so frustrating. Maybe someone does know where is detect leaked activities checkbox?
@@codingwithmitch I did used it but had some strange memory leaks, which I could not figure out to this day. maybe you saw similar messages? stackoverflow.com/questions/53311250/what-does-viewrootlmpl-mattachinfo-means
Very good , and I have a question would you please answer me I made an android app that shows the yearly vacation in a table using sqlite database , and I have the problem of gc because I made a lot of views at the beginning. How can I make the view comes faster because I use a tableview and I add to it textviews. Would you help me ? My name is medo
@@medomody242 why not just use a single textview? Then just append all the data to a StringBuilder or something and display it. Or use a recyclerview if there's thousands.
The example with AsyncTask shown in the video is too simple and more importantly is outdated. In real life nobody uses it. Nowadays developers use either Rx or coroutines. It would be more relevant and valuable to show an example using these technologies.
They should build the LeakCanary logic into the garbage collector
That would make it too easy 😅
yeph i thought it too if LeakCanary can detect why can't collect
I love how you did the animation for the HEAP and GC. I did not know about the Leakcanary and now that I do, I will definitely use it. Thanks
The animations were done by a fan. I really liked what he did.
Yes it was amazing.
Was always curious about the term "Memory Leak", now thanks to you I have a better understanding! Thank you for all your awesome content Mitch!
Excited for more great content 2019 💪🏾
:D
That is definitely good practicing for not using context in a background thread really helpfull video
Nice content it cleared all my doubts about memory leak and gc
Keep it going
Thanks a lot for this. This video helped me understand memory leaks as well as CONTEXTS(which I had been struggling with)
The quality of content you put out is amazing! Keep going!
this was really helpful ! thanks mitch ^^
Great job mitch! when i learn some thing new from mitch i got more energy to learn hard android programming!
This was really very helpful to understand memory leaks, thank you very much, please keep going with these kind of awesome contents:)
Great video. Thanks for the clear illustration.
Bro how do you do on phone?
Great video man. Liked and subbed.
Hi, Mitch.
Good content. Keep up the good works!
I have a memory leak every Saturday when I come home from the Pub, amirite?
(Just kidding, I don't drink)
Haha. I usually have a couple drinks on Friday with my pals. So this is accurate for me. I got up at 1030 this morning and brain didn't feel good
so basically hangover is memory leak ggwp :V .
After much vigorous testing, I can conclude writing code on a hangover makes it much more difficult than it needs to be!
@@davidscammell9823 😆
Are you recording this from inside a box
A Birdbox
V. V. G. V. Vv V. v v v v bbbbbbbbBbBbBBbtbtbtbtbtbtbtbtttttbtbBut. . V. V. . V. . B. . . V. V V. V. V. . V. v. ut. But be. Gg. . G. But v. . od. V. V. G g. . . . . . b But v v. V. be. V. V. tbtbt v . V. . G. @@codingwithmitch
Simple and to the point, really helpful, thank you for making this video:)
I always used this method, now got cleared thanks
Good illustration. Simple and clear, thanks.
How to give more thumbs up instead of only one! :) Love it, so informative!
Great video, thanks Mitch. Looking at Leakcanary I can see they have second version for Kotlin. Will add this to my code!
hey man thank you very much , you always doing what I need , thank you
Very helpful and educational. Thank you, Mitch.
you are amazing mitch..
Thank you so much for explaining this way..it clears all doubts of mine
Amazing video!
Thanks for this great tutorial! Can you please show the error log for the crash?
Excellent Explanation.Good in details.
Really helpful!
thanks a lot for good content waiting for more
@codingwithmitch , Hi can you please make more videos on this topic and also on ANR and High CPU usage topic ?
Good explanation, thanks
very good explanation on memory leak
4:19 The most common way memory leaks occur
Thanks for the video, one question I have is can we Lazy operator instead of WeakReference ?
So, a memory leak happens when a background threat holds a Context or Activity reference, am I correct?
So if I have another normal Java class that holds (requires) a Context or Activity reference but that class does not deal with any background thread, so there would not be any memory leak even though it holds such a reference. Since an object of this class would be gone as soon as the Activity holding that object is gone. Correct me if I was wrong. Because I was so afraid that I manually set the reference to null on each onPause or onDestroy method in an Acticity, in order to make sure the reference would be release :(
So funny to see this video now. "Leak Canary is created by a very well-renowned company called square....". I think you know a lot more about this company now!
Nice ... Please how long have you been using Android studio and Java?
3 years
Well, to be fair, it's not like your background thread never end. Once it ends, its grabbing to the objects also end, and once the next round of GC kick in and it will be collected.
So how is this not causing a crash ? context is garbage collected before asynctask is completed.. effectively null and mContext points to nothing ? or ... ? could you please explain this?
How do I deal with graphics memory? I have tried several times to get any memory leaks, but I have only gotten a memory leak a few days ago, but I have noticed that the graphics memory doesn't go down any. I haven't been able to find anything as far as managing the graphics memory.
Amazing ,Thanks alot
Ok just say I have a context object on a background task but then the associated activity is terminated but it cant be cleaned up, I can understand that the app is then using up more resources than it needs to at this point but when the background task finishes won't the memory be able to be reclaimed by the GC? so what is the big deal if memory is taken up for an extra second or two? Wouldn't this only be a problem on long running background threads?
How about you use an ApplicationContext? Would you still cancel the async on onDestroy?
Great video man!
Any chance you could switch to a dark theme? Will definitely help us nite owls
Thanks. I like white sorry friend.
What if after a while the Garbage collector cleans the memory holding the context object when the activity is destroyed and the weak reference in the AsyncTask is trying to use the context to access a resource for example. Will the App crash? Please help me explain
firstly heap is data structure. secondly when you instantiate some class you write it to heap, not "take it away FROM heap"
It's refreshed after using a movie or camera and going to another app, is there any solution?
so u can just apply this to any one class which extends application class ..?
Very well!
Which emulator are you using?
Vysor, a google chrome extension
Why do you not have Apps on Playstore...It's kinda like teaching stuff when you don't implement it yourself??
I understand what you're saying. The truth is, I haven't had any ideas I think are good enough to invest 1-2 months developing.
CodingWithMitch I'm sorry Mitch Tabian. I wanted to follow your channel with the intent of LEARNING stuff and implementing. You're one of the best at what you do.
Please don't take the comment negatively. I want to see things work for you.
Please try! What if it does
@@exclusiven940 I definitely will. Just waiting for the right time and the right idea.
It's not all heap ... There is also the stack in relation to memory consumption.
Great 😌
where to get code where leak is happening !
Hi mitch, this is a very good tutorial but i am curious
1. if we use LeakCanary then it always shows a notification when there is memeory leak? if we dont want to show these types of notifications to users and want LeakCanary to run in the background for our mess. Can we customize that too??
2. Cant we use java Finalize() too??.
Don't use leak canary in your production build
I dont have any company experience. I am learning from you guys(you and codeinflow and more) . Can you tell us more how we gonna code in professional build and he we can stop memory leak and give us some tips what we should do while making a professional build.
Cooool...It is so simple
Doesn't this memory leak stop as soon as AsyncTask is finished? It other words, 5 seconds? You could argue the AsyncTask can be running on for a long time after that. SURE, but then thats the problem: you're running AsyncTask in the background for no good reason. This is a much bigger problem than having reference to the activity since you might be doing some work on that thread and holding resources.
TLDR: I believe this video highlights how to program badly with AsyncTask (then fixes it). It doesn't show a real-life case of memory leak.
can you create a tutorial for ANR "Application Not Responding" (ANR)
Thanks for the video, but the leakcanary is not showing any leaks for me. I used your code from the video and I ran my app on emulator and physical device.
Learned a heap, (Pun intended) thanks heaps
still leaking memory with this approach while loading next activity
Is the Android garbage collector different than Java's?
Not covered all the possible cases
Helpful
how to prevent memory leak because of view in previous activity's fragment..????..
Did leak canary tell you it's leaking?
@@codingwithmitch yes it points to normal relative layout. But I can't find why because that layout is not static and also not accessing in any background process it always on ui thread.
@@ankitrajdwivedi996 Did you instantiate the fragment using the new instance method?
@@codingwithmitch yes some places I have but in some places adding through the fragment transaction.. both places I have that issue...
@@ankitrajdwivedi996 post a gist containing the code causing an error
setting up LeakCanary as we speak........
AWSOME
Wow, just searched in google by recent and this video appeared... I can't use memory profiler in android 3.0 to find memory leaks.. It is so frustrating. Maybe someone does know where is detect leaked activities checkbox?
Use leak canary
@@codingwithmitch I did used it but had some strange memory leaks, which I could not figure out to this day. maybe you saw similar messages? stackoverflow.com/questions/53311250/what-does-viewrootlmpl-mattachinfo-means
@@viktorvostrikov9625 I'm not sure. I don't see anything in the code you provided that would explain what Leak Canary is saying.
nice, tnx
Very good , and I have a question would you please answer me
I made an android app that shows the yearly vacation in a table using sqlite database , and I have the problem of gc because I made a lot of views at the beginning. How can I make the view comes faster because I use a tableview and I add to it textviews. Would you help me ? My name is medo
I'm not going to review your code or help you code, but you can ask me a specific question and I can try to help.
My question is how to load thousands of textviews inside a tableview in a short time without gc affect ?
I need only an advice from you Mr
And thank you very much cause really all what you do is helpful and high class
@@medomody242 why not just use a single textview? Then just append all the data to a StringBuilder or something and display it. Or use a recyclerview if there's thousands.
I tried this Mr but I have a big scroll table one column fixed with recyclerview it scroll only one row but I need all to be scrolled
The example with AsyncTask shown in the video is too simple and more importantly is outdated. In real life nobody uses it. Nowadays developers use either Rx or coroutines. It would be more relevant and valuable to show an example using these technologies.
Application memory à supprimer
what's your emulator?
vysor, a google chrome extension
Nice to see ur face and not hear ur cool voice only 😁.
p
Thank you so much for explaining this way..it clears all doubts of mine