Memory Leaks on Android

Поділитися
Вставка
  • Опубліковано 2 гру 2024

КОМЕНТАРІ • 112

  • @codinginflow
    @codinginflow 5 років тому +47

    They should build the LeakCanary logic into the garbage collector

    • @codingwithmitch
      @codingwithmitch  5 років тому +14

      That would make it too easy 😅

    • @zameelnm2365
      @zameelnm2365 4 роки тому +1

      yeph i thought it too if LeakCanary can detect why can't collect

  • @samha1513
    @samha1513 5 років тому +16

    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

    • @codingwithmitch
      @codingwithmitch  5 років тому +5

      The animations were done by a fan. I really liked what he did.

    • @samha1513
      @samha1513 5 років тому +2

      Yes it was amazing.

  • @napalm_exe
    @napalm_exe 5 років тому +6

    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!

  • @Rassy_
    @Rassy_ 5 років тому +7

    Excited for more great content 2019 💪🏾

  • @dawoodamir2011
    @dawoodamir2011 5 років тому +6

    That is definitely good practicing for not using context in a background thread really helpfull video

  • @GAMITECH_RK03
    @GAMITECH_RK03 3 роки тому +1

    Nice content it cleared all my doubts about memory leak and gc
    Keep it going

  • @tekenat
    @tekenat 4 роки тому

    Thanks a lot for this. This video helped me understand memory leaks as well as CONTEXTS(which I had been struggling with)

  • @andrej753
    @andrej753 5 років тому +1

    The quality of content you put out is amazing! Keep going!

  • @seifeldenehab3763
    @seifeldenehab3763 4 роки тому +1

    this was really helpful ! thanks mitch ^^

  • @b.k4142
    @b.k4142 5 років тому

    Great job mitch! when i learn some thing new from mitch i got more energy to learn hard android programming!

  • @corporateworld7gl6re8h
    @corporateworld7gl6re8h 3 роки тому

    This was really very helpful to understand memory leaks, thank you very much, please keep going with these kind of awesome contents:)

  • @shivamprasad782
    @shivamprasad782 3 роки тому +1

    Great video. Thanks for the clear illustration.

    • @kinleyk3759
      @kinleyk3759 2 роки тому

      Bro how do you do on phone?

  • @M1A2_Abrams_MBT
    @M1A2_Abrams_MBT 3 роки тому

    Great video man. Liked and subbed.

  • @agungkurniawan4078
    @agungkurniawan4078 5 років тому

    Hi, Mitch.
    Good content. Keep up the good works!

  • @codinginflow
    @codinginflow 5 років тому +12

    I have a memory leak every Saturday when I come home from the Pub, amirite?
    (Just kidding, I don't drink)

    • @codingwithmitch
      @codingwithmitch  5 років тому +8

      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

    • @babintandukar8917
      @babintandukar8917 5 років тому +1

      so basically hangover is memory leak ggwp :V .

    • @davidscammell9823
      @davidscammell9823 4 роки тому +1

      After much vigorous testing, I can conclude writing code on a hangover makes it much more difficult than it needs to be!

    • @codinginflow
      @codinginflow 4 роки тому

      @@davidscammell9823 😆

  • @codinginflow
    @codinginflow 5 років тому +16

    Are you recording this from inside a box

    • @codingwithmitch
      @codingwithmitch  5 років тому +13

      A Birdbox

    • @sexchrist9966
      @sexchrist9966 4 роки тому

      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

  • @harinarayananv.m989
    @harinarayananv.m989 5 років тому

    Simple and to the point, really helpful, thank you for making this video:)

  • @ShivamSharma-kv6bf
    @ShivamSharma-kv6bf 3 роки тому

    I always used this method, now got cleared thanks

  • @hotony4092
    @hotony4092 5 років тому

    Good illustration. Simple and clear, thanks.

  • @mytubekt
    @mytubekt 5 років тому

    How to give more thumbs up instead of only one! :) Love it, so informative!

  • @davidscammell9823
    @davidscammell9823 4 роки тому

    Great video, thanks Mitch. Looking at Leakcanary I can see they have second version for Kotlin. Will add this to my code!

  • @techmarinar
    @techmarinar 3 роки тому

    hey man thank you very much , you always doing what I need , thank you

  • @CiprianBindiu
    @CiprianBindiu 5 років тому

    Very helpful and educational. Thank you, Mitch.

  • @mformobileapps
    @mformobileapps 3 роки тому

    you are amazing mitch..

  • @rahulabrol2211
    @rahulabrol2211 5 років тому

    Thank you so much for explaining this way..it clears all doubts of mine

  • @JoelMathewmatgoogle
    @JoelMathewmatgoogle 4 роки тому

    Amazing video!

  • @sha17187
    @sha17187 4 роки тому +1

    Thanks for this great tutorial! Can you please show the error log for the crash?

  • @bjugdbjk
    @bjugdbjk 5 років тому

    Excellent Explanation.Good in details.

  • @toseefalikhan2297
    @toseefalikhan2297 5 років тому +1

    Really helpful!

  • @AmitVerma-iq3oe
    @AmitVerma-iq3oe 5 років тому +1

    thanks a lot for good content waiting for more

  • @sagarprajapati8769
    @sagarprajapati8769 4 роки тому

    @codingwithmitch , Hi can you please make more videos on this topic and also on ANR and High CPU usage topic ?

  • @oleksandrgrument7948
    @oleksandrgrument7948 5 років тому +1

    Good explanation, thanks

  • @SAROJKUMAR-rr1rr
    @SAROJKUMAR-rr1rr 4 роки тому

    very good explanation on memory leak

  • @isahjade1903
    @isahjade1903 2 роки тому

    4:19 The most common way memory leaks occur

  • @RatneshNavlakhe
    @RatneshNavlakhe 2 роки тому

    Thanks for the video, one question I have is can we Lazy operator instead of WeakReference ?

  • @lucienchu9649
    @lucienchu9649 4 роки тому

    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 :(

  • @robertpeschke7746
    @robertpeschke7746 Рік тому

    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!

  • @rockson6839
    @rockson6839 5 років тому +1

    Nice ... Please how long have you been using Android studio and Java?

  • @smonkey001
    @smonkey001 2 роки тому

    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.

  • @michealandretis7243
    @michealandretis7243 3 роки тому

    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?

  • @darrinreed8027
    @darrinreed8027 3 роки тому

    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.

  • @minarezkalla4403
    @minarezkalla4403 3 роки тому

    Amazing ,Thanks alot

  • @plunkettdog8304
    @plunkettdog8304 4 роки тому

    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?

  • @jimpauloovejera2599
    @jimpauloovejera2599 3 роки тому

    How about you use an ApplicationContext? Would you still cancel the async on onDestroy?

  • @safees3165
    @safees3165 5 років тому +1

    Great video man!
    Any chance you could switch to a dark theme? Will definitely help us nite owls

  • @georgeclinton2727
    @georgeclinton2727 4 роки тому

    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

  • @telephon3208
    @telephon3208 2 роки тому

    firstly heap is data structure. secondly when you instantiate some class you write it to heap, not "take it away FROM heap"

  • @uio86a
    @uio86a 2 роки тому

    It's refreshed after using a movie or camera and going to another app, is there any solution?

  • @babintandukar8917
    @babintandukar8917 5 років тому

    so u can just apply this to any one class which extends application class ..?

  • @user-sankarsana
    @user-sankarsana 5 років тому

    Very well!
    Which emulator are you using?

  • @exclusiven940
    @exclusiven940 5 років тому +2

    Why do you not have Apps on Playstore...It's kinda like teaching stuff when you don't implement it yourself??

    • @codingwithmitch
      @codingwithmitch  5 років тому +2

      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.

    • @exclusiven940
      @exclusiven940 5 років тому

      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

    • @codingwithmitch
      @codingwithmitch  5 років тому +1

      @@exclusiven940 I definitely will. Just waiting for the right time and the right idea.

  • @Leonzkyhv
    @Leonzkyhv 4 роки тому

    It's not all heap ... There is also the stack in relation to memory consumption.

  • @himanshukandwal1374
    @himanshukandwal1374 4 роки тому

    Great 😌

  • @anujgoyal5253
    @anujgoyal5253 7 місяців тому

    where to get code where leak is happening !

  • @amanaggarwal5884
    @amanaggarwal5884 3 роки тому

    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??.

    • @codingwithmitch
      @codingwithmitch  3 роки тому

      Don't use leak canary in your production build

    • @amanaggarwal5884
      @amanaggarwal5884 3 роки тому

      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.

  • @ЕвгенийСокирко-д1в

    Cooool...It is so simple

  • @ben6
    @ben6 3 роки тому

    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.

  • @omkarpawar1741
    @omkarpawar1741 5 років тому

    can you create a tutorial for ANR "Application Not Responding" (ANR)

  • @yumyum17
    @yumyum17 5 років тому

    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.

  • @progtom7585
    @progtom7585 3 роки тому +1

    Learned a heap, (Pun intended) thanks heaps

  • @AbdullahKhan-qn6nu
    @AbdullahKhan-qn6nu 4 роки тому

    still leaking memory with this approach while loading next activity

  • @josephmolina5477
    @josephmolina5477 5 років тому

    Is the Android garbage collector different than Java's?

  • @workmanager2008
    @workmanager2008 5 років тому

    Not covered all the possible cases

  • @ummelaila4628
    @ummelaila4628 Рік тому

    Helpful

  • @ankitrajdwivedi996
    @ankitrajdwivedi996 5 років тому

    how to prevent memory leak because of view in previous activity's fragment..????..

    • @codingwithmitch
      @codingwithmitch  5 років тому

      Did leak canary tell you it's leaking?

    • @ankitrajdwivedi996
      @ankitrajdwivedi996 5 років тому

      @@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.

    • @codingwithmitch
      @codingwithmitch  5 років тому

      @@ankitrajdwivedi996 Did you instantiate the fragment using the new instance method?

    • @ankitrajdwivedi996
      @ankitrajdwivedi996 5 років тому

      @@codingwithmitch yes some places I have but in some places adding through the fragment transaction.. both places I have that issue...

    • @codingwithmitch
      @codingwithmitch  5 років тому +1

      @@ankitrajdwivedi996 post a gist containing the code causing an error

  • @dbtechprojects2392
    @dbtechprojects2392 3 роки тому

    setting up LeakCanary as we speak........

  • @MaisUmSomente
    @MaisUmSomente 3 роки тому

    AWSOME

  • @viktorvostrikov9625
    @viktorvostrikov9625 5 років тому

    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
      @codingwithmitch  5 років тому

      Use leak canary

    • @viktorvostrikov9625
      @viktorvostrikov9625 5 років тому

      @@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

    • @codingwithmitch
      @codingwithmitch  5 років тому

      @@viktorvostrikov9625 I'm not sure. I don't see anything in the code you provided that would explain what Leak Canary is saying.

  • @hamidmahmoodi6690
    @hamidmahmoodi6690 4 роки тому

    nice, tnx

  • @medomody242
    @medomody242 5 років тому

    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

    • @codingwithmitch
      @codingwithmitch  5 років тому

      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.

    • @medomody242
      @medomody242 5 років тому

      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

    • @medomody242
      @medomody242 5 років тому +1

      And thank you very much cause really all what you do is helpful and high class

    • @codingwithmitch
      @codingwithmitch  5 років тому

      @@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.

    • @medomody242
      @medomody242 5 років тому

      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

  • @RenatKaitmazov
    @RenatKaitmazov 4 роки тому

    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.

  • @robertmaurin349
    @robertmaurin349 5 років тому

    Application memory à supprimer

  • @mohamamdhassanrezaeitabar3695
    @mohamamdhassanrezaeitabar3695 5 років тому

    what's your emulator?

  • @bukunmi6378
    @bukunmi6378 5 років тому

    Nice to see ur face and not hear ur cool voice only 😁.

  • @tamiatyesha1552
    @tamiatyesha1552 4 роки тому

    p

  • @rahulabrol2211
    @rahulabrol2211 5 років тому +3

    Thank you so much for explaining this way..it clears all doubts of mine