Stack and Heap: Memory Management In Java (The most important Concept in Java)

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 ก.ค. 2024
  • From Java Code to Java Heap: Understanding the Memory Usage of Your Application:
    Understanding JVM Memory Model, Java Memory Management are very important if you want to understand the working of Java Garbage Collection.
    You might think that if you are programming in Java, what do you need to know about how memory works? Java has automatic memory management, a nice and quiet garbage collector that quietly works in the background to clean up the unused objects and free up some memory.
    Therefore, you as a Java programmer do not need to bother yourself with problems like destroying objects, as they are not used anymore. However, even if this process is automatic in Java, it does not guarantee anything. By not knowing how the garbage collector and
    Java memory is designed, you could have objects that are not eligible for garbage collecting, even if you are no longer using them.
    So knowing how memory actually works in Java is important, as it gives you the advantage of writing high-performance and optimized applications that will never ever crash with an OutOfMemoryError.
    On the other hand, when you find yourself in a bad situation, you will be able to quickly find the memory leak.
    ~~~~~Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:
    th-cam.com/users/Naveen%20Au...
    Follow me on my Facebook Page:
    / naveenqtpexpert
    Let's join our Automation community for some amazing knowledge sharing and group discussion:
    t.me/joinchat/COJqZQ4enmEt4JA... Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:
    th-cam.com/users/Naveen%20Au...
    Follow me on my Facebook Page:
    / naveenqtpexpert
    Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:
    t.me/joinchat/COJqZUPB02r5sB7...
    Paid courses (Recorded) videos:
    Java & Selenium Course: www.naveenautomationlabs.com/p...
    API Course: www.naveenautomationlabs.com/p... ➡️Get Our Courses✔️
    📗 Get My Paid Courses at
    Paid courses (Recorded) videos:
    Java & Selenium Course: www.naveenautomationlabs.com/p...
    API Course: www.naveenautomationlabs.com/p...
    -------------------------------
    ✔️SOCIAL NETWORKS
    Facebook: / naveenqtpexpert
    Twitter: / naveenkhunteta
    Blog: www.naveenautomationlabs.com
    --------------------------------
    Support My Channel✔️Or Buy Me A Coffee
    Paypal: paypal.me/naveenkhunteta
    Google Pay: naveenanimation20@gmail.com
    --------------------------------
    ✔️Thanks for watching!
    देखने के लिए धन्यवाद
    Благодаря за гледането
    感谢您观看
    Merci d'avoir regardé
    Grazie per la visione
    Gracias por ver
    شكرا للمشاهدة
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 147

  • @bibekkumarbazaz647
    @bibekkumarbazaz647 4 ปีที่แล้ว +35

    The best video on memory management that I have come across. It gives a clear insight on how to write memory efficient code in Java.
    Will appreciate if you can make a video on streaming and how it works internally.
    Thanks a ton.

  • @meditationandrelaxationmus741
    @meditationandrelaxationmus741 5 ปีที่แล้ว +2

    never found so detailed.... thanks a ton!

  • @akado5663
    @akado5663 6 ปีที่แล้ว +5

    Thanks a lot Naveen. That was a Video which I was looking for it but never could find. Thanks for the excellent explanation.

  • @techy0716
    @techy0716 2 ปีที่แล้ว +1

    Best illustrated concept of memory management in java

  • @jaserq
    @jaserq 4 ปีที่แล้ว

    Just thank you.. i relieved finally.. i ve been seaching this for years !!!

  • @vijayragavendran5606
    @vijayragavendran5606 5 ปีที่แล้ว

    This is perfect! Great job man ! Thanks a lot!

  • @NikitaKoselev
    @NikitaKoselev 4 ปีที่แล้ว +1

    Great video. JVM understanding is important not only for interviews but far beyond interviews.

  • @jalalzoon4447
    @jalalzoon4447 6 ปีที่แล้ว

    Sir you have clear all concepts regarding java memory management. Thanks for your such great efforts in making video.

  • @GAGamingLegends
    @GAGamingLegends 3 ปีที่แล้ว +4

    This video deserves more likes and views 🙏

  • @niloybasu6508
    @niloybasu6508 2 ปีที่แล้ว +1

    Awesome explanation!!! Terrific!! Thanks a lot!!!

  • @yashasvirallabandi9070
    @yashasvirallabandi9070 ปีที่แล้ว +1

    Great explanation. Thank you!

  • @prabhatpatnaik205
    @prabhatpatnaik205 3 ปีที่แล้ว +1

    really it is very nice video, after read this, I clear my concept on memory heap and stack. thank you navin.

  • @ananthasubramanian7355
    @ananthasubramanian7355 3 ปีที่แล้ว +1

    Very good video....!! Crisp and Clear...!!! Thank you...!!

  • @chetanyewale4457
    @chetanyewale4457 3 ปีที่แล้ว +4

    Great explanation. I read that from Java 8 onwards the permgen has been removed. And instead of permgen we have a metaspace which is part of the native memory (which is not a heap memory) which is managed by the OS.

  • @javierpeniche6720
    @javierpeniche6720 3 ปีที่แล้ว

    Muchisimas graciasssssss, sigue subiendo mas videos de este tipo

  • @achillesheel7314
    @achillesheel7314 5 ปีที่แล้ว

    Excellent! Thank you so much.

  • @shipraparihar6963
    @shipraparihar6963 4 ปีที่แล้ว +1

    Thanks Naveen for this amazing video. It is full of information and explained very clearly.

  • @prapasup
    @prapasup 5 ปีที่แล้ว +1

    Thanks much for sharing the information.

  • @madhulikaghosh3876
    @madhulikaghosh3876 5 ปีที่แล้ว +2

    Thankyou Naveen. This was so informational

  • @user-lv4up4io6y
    @user-lv4up4io6y 4 หลายเดือนก่อน

    Great knowledge you having sir. Thanks for this .

  • @aritrabhattacharya7722
    @aritrabhattacharya7722 2 ปีที่แล้ว

    This was really helpful. Thanks a lot.

  • @saranthoughts9826
    @saranthoughts9826 4 หลายเดือนก่อน

    I am always follow your channel for java related , you rocking pls keep doing the good work. great sir!❤

  • @parikshitraghav7543
    @parikshitraghav7543 4 ปีที่แล้ว +3

    I Like your efforts Naveen, Very very useful video for interview (I was asked these questions in mine!).

  • @MrSpraveennaika
    @MrSpraveennaika 2 ปีที่แล้ว +1

    My first nice video on Memory Management 👌👌

  • @ahmadreza7508
    @ahmadreza7508 3 ปีที่แล้ว

    Thank you so much for creating such a helpful video

  • @nandagopal375
    @nandagopal375 ปีที่แล้ว +1

    Thank you provide valuable information about Java memory management 🙏🙏🙏

  • @avishsharma3404
    @avishsharma3404 3 ปีที่แล้ว

    Great Explanation , this is something that I found deepen understanding of memory management. Thanks Naveen

  • @sourabhhsethii7292
    @sourabhhsethii7292 3 ปีที่แล้ว

    Thanks for sharing this knowledge!

  • @praveenautomationinterview2367
    @praveenautomationinterview2367 6 ปีที่แล้ว +7

    Hi Naveen,
    as always this is nice explanation!!
    Can we say that :Java Stack memory=Class (method) area+Native Method Stack+Variables memory area

  • @SeadoooRider
    @SeadoooRider 3 ปีที่แล้ว +1

    I really appreciate your effort Naveen. Thanks for video :)

  • @ayyapareddykandula8481
    @ayyapareddykandula8481 5 ปีที่แล้ว +1

    Excellent sir, thanks for the video

  • @jeetupadhyaya2687
    @jeetupadhyaya2687 2 ปีที่แล้ว

    Thankyou for this video Naveen!

  • @bollywoodtrailers7913
    @bollywoodtrailers7913 4 ปีที่แล้ว

    It was really a very explanatory session.
    Got all the concept by this vesio

  • @sureshgply
    @sureshgply 6 ปีที่แล้ว

    Very good explanation for Memory management. Thanks Naveen

  • @ABAutomationHub
    @ABAutomationHub 2 ปีที่แล้ว +1

    Best content on memory management..Thanks for sharing!

    • @naveenautomationlabs
      @naveenautomationlabs  2 ปีที่แล้ว

      Thanks glad you liked it. Please refer the latest video on java memory management

  • @_________________404
    @_________________404 4 ปีที่แล้ว +1

    Thanks, very interesting video. I just wanted to see what is the diference between local and static variable storage but I've learned much more.

  • @ramyapalani6760
    @ramyapalani6760 5 ปีที่แล้ว

    Hats off sir..very good explanation..
    Pls continue this topic to cover garbage collection..

  • @parwana1000
    @parwana1000 3 ปีที่แล้ว

    Bow down to u ...TY so much

  • @Priya1_123
    @Priya1_123 3 ปีที่แล้ว

    Great and deep explanation and information in detail . Better than all other videos from other youtube channels.. Just a small suggestion, if the diagram is ready then this video can be covered in bit less time.Awesome video. Thanks a ton

  • @khajazakiuddin931
    @khajazakiuddin931 5 ปีที่แล้ว

    u really make it simple naveen... 😊...i still like ur amazing diagrammatic representation of concepts which make things really easy to understand...kudos bro... keep going...👏🙂

  • @princekumar764
    @princekumar764 6 ปีที่แล้ว

    one word....AWESOME

  • @GauravSingh-ov9mh
    @GauravSingh-ov9mh 6 ปีที่แล้ว +3

    Great video. Just had a couple of query : 1. You said permgen is part of stack memory but you displayed them on separate boxes so that was confusing.
    2. You said stack size is very less compared to heap memory. but than what about Permgen (or now Metaspace) . Is metaspace is less compared to heap?
    Thanks!

  • @pragadees24
    @pragadees24 6 ปีที่แล้ว +1

    Very Good One:) got some more Idea about JRE.

  • @AshutoshSingh-uc6nk
    @AshutoshSingh-uc6nk 3 ปีที่แล้ว +1

    Thankyou sir for this 🔥🔥🔥 explanation

  • @supriyakumari8552
    @supriyakumari8552 3 ปีที่แล้ว

    great information, fine details. :)

  • @mhdsibu2533
    @mhdsibu2533 5 ปีที่แล้ว

    Its really helpfull..thank you

  • @sreevanireddy1325
    @sreevanireddy1325 4 ปีที่แล้ว

    Every Nice explanation sir, it's very clear to understand. Thank you sir.

  • @kshitij618
    @kshitij618 2 ปีที่แล้ว

    awesome man

  • @swapnilgupta6028
    @swapnilgupta6028 5 ปีที่แล้ว +1

    Thank you so much Naveen but one Question, Cam you tell from which book you took reference ?

  • @saishekhar5847
    @saishekhar5847 5 ปีที่แล้ว

    Thanks bro great job. thank u

  • @asimghosh5737
    @asimghosh5737 3 ปีที่แล้ว +1

    Very nice👍👍👍 it's really helpful.

  • @arijitbasu4397
    @arijitbasu4397 3 ปีที่แล้ว

    Such a quality content ❤️

  • @ayushjain7555
    @ayushjain7555 ปีที่แล้ว

    Thank you.

  • @nishant2242
    @nishant2242 2 ปีที่แล้ว

    Great explanation

  • @nalithamsaisudha
    @nalithamsaisudha 2 ปีที่แล้ว

    great explanation 👏

  • @narainsankar
    @narainsankar 3 ปีที่แล้ว

    Great explanation..

  • @ThishK
    @ThishK 6 ปีที่แล้ว

    Great one!! One question to you Naveen. Do you know how to perform test for the product (Web based Game) where DOM element is hidden. I think all the DOM element is under the CANVAS?

  • @zajuzam
    @zajuzam 2 ปีที่แล้ว

    Nice Explanation

  • @ramprasath4788
    @ramprasath4788 4 ปีที่แล้ว

    Clearly explained ....

  • @soundhermm5514
    @soundhermm5514 6 ปีที่แล้ว +1

    Good explanation

  • @gyaraganesh7020
    @gyaraganesh7020 5 ปีที่แล้ว

    sir , your explanation is very nice
    and make more videos
    thanking you very much sir

  • @beingapt
    @beingapt 4 ปีที่แล้ว

    Thanks a lot.

  • @dilipp007
    @dilipp007 6 ปีที่แล้ว +1

    One of the survivor memories will always be free..

  • @SureshKumar-ul5ev
    @SureshKumar-ul5ev 5 ปีที่แล้ว +1

    Custom immutable store into which part of memory?

  • @namangoyal5578
    @namangoyal5578 4 ปีที่แล้ว

    Great Work, I searched so many videos but this is my final stop !!
    Appreciate the efforts you did to make this :)
    One doubt : Is permanent generation the part of Stack Memory ???

  • @saikiran2356
    @saikiran2356 2 ปีที่แล้ว

    Kutha chimpi para dhengaw anna.... Mid nyt kuda chaala interesting ga chusaa

  • @mayank9266
    @mayank9266 4 ปีที่แล้ว

    Thank you sir 🔥🔥

  • @shashankjakhmola6226
    @shashankjakhmola6226 2 ปีที่แล้ว

    If Test t = new Test() is defined as instance variable rather then defined inside some method like m1 method. In that case I understood that new test() will be creating one object inside the heap. But where the reference will be stored as it is not local variable it is instance variable ? And stack will store local variable and local references as much as i know?

  • @amanokuba4688
    @amanokuba4688 4 ปีที่แล้ว

    Nice explanation, thank you...As for the back ground noise, you could add a faint background music to cancel and soften the high pitch noise....

  • @nikhilgupta6564
    @nikhilgupta6564 6 ปีที่แล้ว +1

    Very well explained .. Concise and clear .. Pls keep uploading more videos on JAVA

  • @rachanabanerjee4696
    @rachanabanerjee4696 5 ปีที่แล้ว +1

    One of the best tutors you are Naveen.

  • @mallikarjun-shurpali9698
    @mallikarjun-shurpali9698 ปีที่แล้ว

    Nice explanation sir..

  • @user-yq4gb5vu6f
    @user-yq4gb5vu6f 5 หลายเดือนก่อน

    how you differing method block and method area of Permanent generation.

  • @nathansmalley8433
    @nathansmalley8433 3 ปีที่แล้ว

    Ty. Good explanation

  • @shubhamtripathi6536
    @shubhamtripathi6536 5 ปีที่แล้ว

    which method block is stored in stack in case of method overriding?

  • @sanbitroy6081
    @sanbitroy6081 6 ปีที่แล้ว +1

    Awesome

  • @stabgan
    @stabgan 5 ปีที่แล้ว +2

    Thanks boss

  • @RanjithKumar-qj9mn
    @RanjithKumar-qj9mn 4 ปีที่แล้ว

    Thanks Naveen . I have a question is premgen is also part of stack memory

  • @AhmedKhaled-he9mf
    @AhmedKhaled-he9mf 2 ปีที่แล้ว

    very very nice explain
    I become subscriber because this video

  • @chigullapallysaiprasad6395
    @chigullapallysaiprasad6395 6 ปีที่แล้ว +1

    Naveen ji extraordinary teaching thanks a lot for sharing your great knowledge please help in sql concepts as well.

  • @dProfessor_
    @dProfessor_ ปีที่แล้ว

    Thanks Sir

  • @LuckySingh-mx7tb
    @LuckySingh-mx7tb 5 ปีที่แล้ว

    very very nice....

  • @aritrabhattacharya7722
    @aritrabhattacharya7722 2 ปีที่แล้ว

    Hello Sir, I have some questions:
    So where exactly are new Strings stored (in heap or in stringpool directly)? And where is the stringpool located then (method area of permgen or heap)? There has been some changes in Java 7 and 8 to the permgen section. When does a string automatically move to striingpool provided intern methos is not called.
    Thanks in advance :)

  • @shashankjakhmola6226
    @shashankjakhmola6226 2 ปีที่แล้ว

    Memory leak will come on only in heap area right? If yes then in that case what we need to do in that case?

  • @arunnagarindia
    @arunnagarindia 5 ปีที่แล้ว

    Hi Naveen,
    My Java application reads file and stores to DB.for this it takes 3GB space.but after completion of program GC is not clearing the space, application still takes 3GB space.how to free up the space??

  • @rafiq41cb
    @rafiq41cb 2 ปีที่แล้ว

    If m1 calls m2, method block will be available to which method?

  • @rajajain786
    @rajajain786 3 ปีที่แล้ว

    Hi Naveen, just want to know each application create own JRE on server memory? also what is difference between JVM and JMM?

  • @bipinmaharjan4090
    @bipinmaharjan4090 3 ปีที่แล้ว

    Awesome video. I have one question do i need to run manual gc?

  • @ramprasath5054
    @ramprasath5054 5 ปีที่แล้ว

    Very good

  • @faisalsakib9810
    @faisalsakib9810 5 ปีที่แล้ว +1

    Thanks for such nice videos....can you please tell me after execution of a method... where the result is stored.???

  • @livefantastic2442
    @livefantastic2442 5 ปีที่แล้ว

    very nice video. one question i had, corresponding to each thread is there a separate stack bcoz in case of multiple threads multiple functions may execute simultaneously thus each method need a method block. Though in a particular thread only one method will execute at a time.

  • @somias1575
    @somias1575 3 ปีที่แล้ว

    Hi Naveen, one query on method block. You said one method at a time is given space inside it. But let's say we have a main method which calls another method inside it. How is this scenario handled?

  • @dinkarinjosh
    @dinkarinjosh 4 ปีที่แล้ว

    if Method block is used one by one by the methods being executed, what will happen if one method1 calls another method2 and method2 returns something to method1, at this time both the methods are executing (pseudo parallelly)?

  • @shijocg
    @shijocg 3 ปีที่แล้ว

    Very informative. I have one doubt why the survivor memory classified as two, both have same usage and purpose?

  • @apoorvdixit2856
    @apoorvdixit2856 3 ปีที่แล้ว

    sir can we say that each class have only one object and rest are created by referenced to that object.

  • @sancharidas7532
    @sancharidas7532 2 ปีที่แล้ว

    What are JRE classes? The predefined classes or the ones which I have made ?? Someone help me understand please.

  • @mugeeshhk
    @mugeeshhk 3 ปีที่แล้ว

    As per my understanding,
    1. So at a time, one of the survivor space is always empty ? this correct ?
    2. Objects that are survived after many cycles of GC, are moved to the Old generation memory space ?

  • @shashankjakhmola6226
    @shashankjakhmola6226 2 ปีที่แล้ว

    As much as i have a knowledge till now permanent generation is separate memory are and stack is separate memory area . But in this video somewhere at the end you are saying parmanent memory is part of stack memory which is making me confused can you please explain on that ? Is both separate memory area or parmanent is part of stack. ?

  • @dupindersingh1599
    @dupindersingh1599 3 ปีที่แล้ว

    Question 1:
    At the time of Major GC, will the JRE do only Major GC ? or JRE will perform its normal tasks and in parallel Major GC will perform
    Question 2:
    When you said we don't have to do the Major GC frequently, is there any code we write explicitly for GC? I think JRE itself take care of the Garbage collection.

  • @kunalsinha5942
    @kunalsinha5942 2 ปีที่แล้ว

    Thanks Naveen for such a informative video. I have a follow up question below:-
    If we create any Collection I.e Arraylist , Hashmap etc .. where is it created .. in Heap or Stack?Since collections stores the the object references rather than physical objects..How does it manage the whole process?