Office Hours — Today, October 23

Yesterday, October 22

Oct 23
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
7:30 PM
Emmanuel
has entered the room
Emmanuel
Hey Mark
Mark M.
hello, Emmanuel!
how can I help you today?
Emmanuel
Ok, so I have a question regarding memory leaks
I know that when you declare a Handler as an anonymous inner class of an Activity, you are going to leak it because the inner class holds a reference of its enclosing type
this happens, in my understanding because all Loopers share the same MessageQueue
my question is:
7:35 PM
Emmanuel
can you also leak an Activity with an anonymous inner OnClickListener, for example?
Mark M.
not usually
the problem is that the Handler is held onto by something that lives past the Activity
and if there's a way to make the Handler go away, I'm not familiar with it
Emmanuel
I see
Mark M.
so, if you were to put an OnClickListener in a static data member, that would leak the listener and anything it can reach
and so if that's an anonymous inner class, you'd leak the outer class (e.g., the activity or fragment that created it)
but, usually we don't put an OnClickListener in a static data member
Emmanuel
right
so just passing an anonymous inner OnClickListener, that is not a static member, will not leak the Activity
Mark M.
correct
Emmanuel
thanks
Mark M.
if you have another question, go right ahead -- it's a quiet chat room tonight
Emmanuel
there has been some discussion about this at work, and I wanted a trustful answer, lol
well I actually wanted to thank you for all your work with the Guide and SO
Mark M.
you are very welcoem
er, welcome
Emmanuel
to give you a bit of perspective
7:40 PM
Emmanuel
I started learning how to code less than 2 years ago
and now I develop professionally
actually I am switching jobs in a week or so and moving to NYC
Mark M.
congratulations!
Emmanuel
your book helped me a lot
hopefully I can go to one of your talks in NYC, if there are any
Mark M.
I am glad that you found it useful
I am taking a bit of a break from speaking after my events in October and November
so I do not have anything scheduled in NYC, sorry
Emmanuel
well, but probably it will be more likely that you will go to NYC than to St. Louis
hopefully, lol
Mark M.
since I have never been to St. Louis, other than the airport, that's a fair assessment :-)
7:45 PM
Emmanuel
what do you think of Android 5.0? isn't material design too animation intensive?
Mark M.
Material Design is fine, I guess, for Android 5.0+, but I'm not a big fan of trying to emulate it on older devices
Emmanuel
I agree
Mark M.
though the borderless buttons I'm seeing in 5.0 drive me up a wall
Emmanuel
I haven't even really looked into the SDK in detail
Gabriele
has entered the room
Mark M.
hello, Gabriele!
Emmanuel
I was expecting that Google would have a series of videos to teach us a bit more about Android 5.0
Mark M.
Emmanuel: they will probably release more DevBytes videos in the coming months
Gabriele
hi :)
Mark M.
but let me take a question from Gabriele, and I'll swing back to you in a bit
Gabriele: your turn! do you have a question?
7:50 PM
Gabriele
I have a simple_list_item_single_choice listview with many lines (400-600 ~) and when I fast-scroll the listview, the device lags a bit, can I do something to increase its performance?
Mark M.
that's difficult to answer in the abstract
I'd use tools like Traceview to try to determine where your time is being spent
paying particular attention to your ListAdapter (e.g., getView())
Gabriele
I'm using the holder pattern, don't know if it's important
Mark M.
well, that will help a bit, but you'll want to see if anything related to it is showing up in Traceview as well
Gabriele
I will see inside with traceview then, thank you
Mark M.
also, check LogCat and see if you're getting GC-related log messages while the scrolling is going on (e.g., GC_FOR_ALLOC)
Gabriele
can I run it directly from android studio?
Mark M.
I don't think so
I think you'll have to open the Android Device Monitor, from the Tools > Android menu
7:55 PM
Gabriele
ok, thank you Mark
Mark M.
Emmanuel: your turn! do you have another question?
Emmanuel
Are you going to add Android 5.0 to the Guide?
Mark M.
sure
though, as usual, it will be in pieces
there is stuff from past versions I haven't gotten to either
Emmanuel
will we see some 5.0 on the next release?
Mark M.
I am currently planning on a release in mid-November that will start covering 5.0
and more in future releases, in December and onward
8:00 PM
Emmanuel
great!
Mark M.
but it will not be until 2015 before I get to some of the bigger-ticket items, like RecyclerView
as I have very little time to work on this stuff here in the rest of 2014, due to presentations and training engagements
Emmanuel
I can imagine
Mark M.
if either of you have a question, go right ahead
Emmanuel
are you going to cover dependency injection libs?
Dagger, more specifically
Mark M.
no, in large part because I am not using them anywhere, so I lack experience in the subject
CodeApprentice
has entered the room
CodeApprentice
Hello
Mark M.
hello, CodeApprentice!
8:05 PM
Mark M.
CodeApprentice: I'm kinda in free-for-all mode at the moment, so if you have a question, go right ahead!
CodeApprentice
Emmanuel told me you were online. Just wanted to drop in.
Not sure that I have any specific questions right now, though.
Mark M.
OK
if anyone has any questions, go right ahead
Gabriele
under Heap, from the emulator, I can read a lot of objects and a big percentage of usage (80-100%)
Mark M.
um, I'm sorry, but I don't know what "under Heap" means
Gabriele
the heap tab inside the monitor
8:10 PM
Mark M.
I haven't been in that in a couple of years
("that" meaning the tab that you're referring to)
8:20 PM
CodeApprentice
has left the room
Gabriele
do you remember where I can see the time spent, Mark?
I can't find it
Mark M.
everything in Traceview is about the time spent
there is the timeline by thread at the top
there is the call tree at the bottom
poke through the call tree, looking for references to your ListAdapter and/or ViewHolder classes, and see how much time the reported methods on those are taking up
or, look for other things that seem out of place, in terms of the number of calls, the time taken, etc.
there's also a chapter in the book on Traceview, and another on jank, that might be of use in tracking down your problem
8:25 PM
Gabriele
ok, thank you again, Mark
8:30 PM
Mark M.
that is a wrap for today's chat
the transcript will be posted to http://commonsware.com/office-hours/ shortly
the next chat is Monday at 7:30pm US Eastern Time
have a pleasant day!
Emmanuel
has left the room
Gabriele
has left the room
Mark M.
turned off guest access

Yesterday, October 22

 

Office Hours

People in this transcript

  • CodeApprentice
  • Emmanuel
  • Gabriele
  • Mark Murphy