Pixate / pixate-freestyle-android

Pixate Freestyle for Android
Apache License 2.0
254 stars 55 forks source link

Memory problems #13

Closed dbrouard closed 10 years ago

dbrouard commented 10 years ago

Hi, I'm having lots of problems using freestyle in android. I installed and made it work, but since I added it, I have many out of memory errors. I've optimized my own code and resources, but the only way I have to avoid these hangs is removing freestyle from the app.

I followed the steps and the default.css is very simple. My only answer is that freestyle itself has memory leaks. By now, I have to remove freestyle, at least from this app.

Any idea?

Thanks in advance, Diego.

Shalom commented 10 years ago

Hi Diego, Oh our memory profiling there wasn't anything that stood out as a problem/memory leak, so perhaps there something we missed in a specific scenario or usage. It would be great if you could point out what you see in your app profiling, and where are the hot spots that involve Freestyle. Thanks!

dbrouard commented 10 years ago

I've tried to check the app using MAT, but, honestly, it's very hard to me to understand how it works. Can you give me some steps you need me to do so that I can give you more information?

Shalom commented 10 years ago

I usually use the DDMS tool to create a method-profile snapshot when loading an activity. E.g., hit the 'start memory profile', let the activity load, and then hit the 'stop memory profile'. It will generate a table that will describe what was happening in terms of execution time. For memory profiling, there is a great Google IO talk that explains very nicely how to detect issues - https://www.youtube.com/watch?v=_CruQY55HOk

In this case, the main suspect would be the Bitmaps. If you get to see bitmaps references that are sticking there, that's probably the problem. How does your CSS look like? Also, do you style any lists/spinners?

dbrouard commented 10 years ago

Thanks, I'll have a look at youtube link right now.

About the Bitmaps, yes, the OutOfMemory errors are related to bitmaps all of them and the css is quite simple ( I paste it below ). The only list I style is using the class "sidebar" which I apply programmatically.

action_bar {

background-color:#ffc000;

}

action_bar_title {

color: #ffffff;
font-size: 58px;
font-size: 24px;
text-align:center;

} button { background-color: #FFC000; border-radius: 8px; color: #FFFFFF; font-size: 20px; line-height: 20px; padding: 10px 24px 11px 23px; } button:pressed { background-color: #D6CDB5; color: #FFFFFF; border-radius: 8px; }

init_screen{

background-image:url(bg_body.png);
background-repeat:repeat;

}

honey_description_title,

honey_location_title{

font-size:24px;
color:#B8A466;
font-weight:bold;

}

sell_point_description,

honey_description,

honey_location{

font-size:16px;
color:#B8A466;
line-height:140%;

}

honey_location_image{

border:1px solid #B8A466; 

} .sidebar{ background-color:#fefbea; divider: #b8a466; divider-height: 1px; }

drawer_list_item_name{

color:#b8a466;
font-size:20px;

}

sell_point_comment{

border:1px solid #71674f;

}

sell_point_contact_title,

stock_title{

font-weight:bold;
color:#71674f;

}

honey_flower_image{

border:1px solid #000000;

}

Shalom commented 10 years ago

Ok, this looks like a straight forward CSS. Why programatically, btw? You can add a 'class="sidebar"' in your list layout, and that should work as well. Are you doing anything special in your list adapter?

dbrouard commented 10 years ago

I put the class programmatically because I can't find in the doc how to apply a class at the xml layout, all the examples I've found is applying css to an "id".

About the listview, yes, it's a bit special, as it's a drawer listview

Shalom commented 10 years ago

Ok, what if you just skip only the styling of the list view? List views are getting a bit of a special treatment with Freestyle since recycling is involved. Perhaps something is not aligning well there with your drawer list. Freestyle is actually proxying the adapters to hook up into the recycling process. We replace your adapter with a Proxy (see PXHierarchyListener#setAdapterProxy() and PXAdapterInvocationHandler). To get your original adapter, btw, you can call PixateFreestyle.getAdapter(AdapterView).

dbrouard commented 10 years ago

There is no significant difference. Anyway, I've found some interesting things ( thanks to that awesome video ).

The app with freestyle usually stays at ~15% of free memory, while, without, it stays at ~35%. In this app , images are important and they are used, so I think that freestyle does not have a memory leak, but put the app "in the edge", so, any memory peak becomes fatal.

At least, as I can see, the memory leak is in the app ( I hope I'm fixing it thanks to your video suggestion ), but on the other side, freestyle seems too heavy, at least for this app ( I'm using it in another apps and I haven't had problems by now ).

I really love freestyle, perhaps if I manage to get my app light I will be able to re-enable freestyle.

Thanks for your support!

Shalom commented 10 years ago

No problem :) Let us know if you find any spots we can optimize in Freestyle, or send us a pull request in case you make a change and I'll be happy to take a look.