English subtitles

← Heap Viewer Walkthrough

Get Embed Code
13 Languages

Showing Revision 4 created 05/24/2016 by Udacity Robot.

  1. Okay.
    To get more information on the state of
  2. our memory and
  3. the objects that are taking up space, we
    can use a handy tool called Heap Viewer.
  4. Now with Heap Viewer,
  5. you can see how much memory a process
    is using at certain points in time.
  6. Now as before, if you want to follow
    along, go ahead and start Android Studio
  7. and bring sunshine to the foreground
    on your connected device.
  8. In order to start Heap Viewer, you'll
    want to start Android Device Monitor
  9. first and
    there are a few options to do that.
  10. One way is through the tools menu
    where you can click on tools, android,
  11. and android device monitor.
  12. Or, you can click on this nifty android
    icon here in your tool bar at the top.
  13. So I'm going to do that and
    android device monitor is starting,
  14. then we're going to want to go ahead and
    click the DDMS tab.
  15. The heap viewer is one
    of the DDMS tools and
  16. we're going to go over here to the left.
  17. And we're going to select
    the app we want to profile, so
  18. we're going to select Sunshine now I'm
    going to pull up this panel down here.
  19. So once you have Sunshine selected
    you're going to want to select this heap
  20. tab to get more information.
  21. Now initially you might not see much,
    but you notice this little.
  22. Hint here at the top that reads Heap
    updates will happen after every GC for
  23. this client.
  24. Why don't we go ahead and click on this
    and cause a GC to update your data.
  25. Whoa, look.
  26. We have all this new information now.
  27. Now the table updated and shows you
    what data is currently available and
  28. alive on the Heap.
  29. If you want to get some more details
    go ahead and select a single data type.
  30. I'm going to click this class object.
  31. Now you'll see a lot of data will
    update in the panel down below.
  32. You can now see a histogram for
    the number of allocations and
  33. also the specific memory size for
    that data type.
  34. In this case we're talking
    about the class object.
  35. Now the heap viewer is
    really helpful to see what.
  36. Types of objects your
    application has allocated,
  37. as well as how many and
    what sizes they are on the heap.
  38. Again here, see we see the total sizes.
  39. Of particular types on our heap.
  40. Like for example there's over 1400
    two biter arrays on our heap,
  41. that's taking about 120 kilobytes.
  42. Whereas there are only
    27 one byte arrays and
  43. it's roughly only taking
    up about two megabytes.
  44. Now the heap viewer is really helpful
    to see what types of objects.
  45. You application is allocated.
  46. As well as how many, and
    their respective sizes on the heap.
  47. For example, if we look here we
  48. have 27 one byte arrays that are taking
    up roughly two megabytes of data.
  49. And then we have about 2000 four
  50. byte arrays that are taking up
    currently 228 kilobytes of data.
  51. This information is super helpful
    when you're trying to track down
  52. memory leaks.