Jun 30 | 3:50 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Jun 30 | 4:15 PM |
Susheel | has entered the room |
Susheel |
Hi Mark..how are you?
|
Mark M. |
hello!
|
Mark M. |
sorry for the delay
|
Mark M. |
how can I help you?
|
Susheel |
So I using FragmentStatePagerAdapter to swipe through approximately 100 screens or so...I am using fragment.createinstancemethod to create a new instance of my fragment each time...in my fragment I am making retrofit calls to get back json data including images to parse it and populate in my views accordingly...so about after 40 fragments or so...my app crashes because it runs out of memory as I am observing the memory monitor
|
Jun 30 | 4:20 PM |
Susheel |
no problem!
|
Susheel |
in my onstop method of the fragment, I am canceling the retrofit and asynctask calls...
|
Susheel |
I am somehow leaking memory and not understanding where I could be doing this...
|
Mark M. |
well, you might not be "leaking" memory, so much as just using too much of it
|
Mark M. |
generate a heap dump and see what's all being held onto
|
Susheel |
Right...
|
Mark M. |
for example, you might have a singleton cache of some sort that isn't bound by size or number of elements, so it grows continuously
|
Mark M. |
or, you might have several caches, each of which is individually capped, but that the sum of their caps exceeds available memory
|
Susheel |
hmm...the only singleton I am using is the retrofit api client instance but I get your point...
|
Mark M. |
another technique would be to comment out some portion of the logic and see what happens with memory usage
|
Susheel |
right
|
Mark M. |
for example, you might comment out loading the images, since bitmap management is a common source of OutOfMemoryErrors
|
Susheel |
right! I should try that
|
Mark M. |
if with image-loading commented out, your memory profile is pretty flat, then that's the area to focus on
|
Jun 30 | 4:25 PM |
Susheel |
I have heard not great things about facebook's fresco...apparently the memory management when cleaning up resources is not handled properly...what are your thoughts?
|
Jun 30 | 4:30 PM |
Mark M. |
I haven't used it
|
Mark M. |
I stick with Picasso
|
Mark M. |
but, I haven't written an image-heavy app, either
|
Susheel |
hmm...I use Picasso as well...
|
Mark M. |
well, Picasso has an image cache
|
Mark M. |
I think the default size is 20% of your heap limit, though I may be mis-remembering
|
Mark M. |
and, the size is configurable
|
Susheel |
right
|
Susheel |
I love it
|
Jun 30 | 4:45 PM |
Susheel |
So I commented out the code related to images and I haven't seen a massive memory gain...
|
Mark M. |
OK, well, that suggests that image management is the source of your problems
|
Mark M. |
in theory, if all you are doing is using Picasso, there should not be a problem here
|
Jun 30 | 4:50 PM |
Mark M. |
you might want to do that heap dump, search for Bitmap instances, and see what's all being held, and by what
|
Mark M. |
or, temporarily disable the Picasso memory cache (which I think you can do), and see what happens
|
Jun 30 | 4:55 PM |
Susheel |
actually I am using fresco here
|
Susheel |
sorry I didn't mention
|
Mark M. |
oh, I misunderstood
|
Mark M. |
I don't have a lot of advice with respect to that, sorry
|
Susheel |
and I meant I didn't see a memory gain which means the problem maybe isn't with the images
|
Mark M. |
oh, sorry, I misunderstood twice -- I thought you meant that you were not leaking memory
|
Mark M. |
or, rather, that you were not increasing your memory usage
|
Mark M. |
so, if it's not the images, you will need to determine what else large you have that might be the source of the difficulty
|
Susheel |
no problem...can i just ask you if my implementation is ideal? the fact that I am making retrofit calls in the fragment and updating the views?
|
Mark M. |
the reason why bitmaps tend to be a problem is that they are usually the biggest single chunks of memory we have
|
Susheel |
or should I use a service or something like that?
|
Mark M. |
I can't really say whether that is a good thing or a bad thing
|
Mark M. |
a service would only be needed if you intended to do this I/O even if the user stepped away from the activity
|
Susheel |
right
|
Susheel |
it's not...so service is probably not ideal here
|
Mark M. |
it should not be needed
|
Mark M. |
so, I'm back to the heap dump suggestion, annoying as those are to try to make sense of
|
Jun 30 | 5:00 PM |
Susheel |
I should learn how to interpret the heap dump first...
|
Susheel |
haha
|
Mark M. |
and that's a wrap for today's chat
|
Susheel |
thank you Mark
|
Mark M. |
the transcript will be posted to https://commonsware.com/office-hours/ shortly
|
Mark M. |
the next chat is 4pm US Eastern on Tuesday
|
Mark M. |
you are very welcome!
|
Mark M. |
have a pleasant day!
|
Susheel | has left the room |
Mark M. | turned off guest access |