android-developers
[Arriba] [Todas las Listas]

Re: [android-developers] Re: Tracking Abajo casos de Actividad múltiple

To: android-developers@xxxxxxxxxxxxxxxx
Subject: Re: [android-developers] Re: Tracking Abajo casos de Actividad múltiple en memoria
From: Kostya Vasilyev <kmansoft@xxxxxxxxx>
Date: Thu, 18 Sep 2014 01:54:02 +0400
Delivery-date: Thu, 18 Sep 2014 00:20:05 -0400
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:list-post:list-help:list-archive :sender:list-subscribe:list-unsubscribe:content-type; bh=mUdaUj8BhuGAqlgsIHbthZpo2aFtBzZ/n6nvSUVeyZo=; b=hWtlRs64Y4G8Av6SFIwwnYV5i5iKLtntmhICWJCWWSmZVdn4eqgeZB9yaX/xWX9+Ou 0PqDGywJzhlMyXx712HhpI8pU/fjBgMImTBHz+Ig6TIkOURRmM1aRWVgxhv/k6sX9kcs jIaVG1wQIKYXis1SxMA3RDSRmdOyjAJkJ4ggYGxqDKK7EXnBR4xvnXs2x7GkgnAolliX ChHl7uXQaqrXC9UXzRdul4dmWz0lQF4w7uosX5vUp6MjVBepJ4LxU2+KS0gMOQpb5R/a 3oNbrGsK9dHvhIut3S2yN4f24dtB7MpabcaHNkJuM4FfX7H65yVAOzHT8JQU8EuALndB EWog==
Envelope-to: traductor@xxxxxxxxxxx
In-reply-to: <674c72a6-4b9f-46bf-8630-e385cf11284c@googlegroups.com>
List-archive: <http://groups.google.com/group/android-developer>
List-help: <http://groups.google.com/support/>, <mailto:android-developers+help@googlegroups.com>
List-id: <android-developers.googlegroups.com>
List-post: <http://groups.google.com/group/android-developers/post>, <mailto:android-developers@googlegroups.com>
List-subscribe: <http://groups.google.com/group/android-developers/subscribe>, <mailto:android-developers+subscribe@googlegroups.com>
List-unsubscribe: <mailto:googlegroups-manage+364598216046+unsubscribe@googlegroups.com>, <http://groups.google.com/group/android-developers/subscribe>
Mailing-list: list android-developers@xxxxxxxxxxxxxxxx; contact android-developers+owners@xxxxxxxxxxxxxxxx
References: <75fe8bab-ade3-4f65-b2f7-cc2bc18cb1a1@googlegroups.com> <43640fe8-9cba-4173-9bc1-871e1b918562@googlegroups.com> <674c72a6-4b9f-46bf-8630-e385cf11284c@googlegroups.com>
Reply-to: android-developers@xxxxxxxxxxxxxxxx
Sender: android-developers@xxxxxxxxxxxxxxxx
En mi experiencia, *WeakReferences es recogido bastante *aggressively por
*Android 2.3 y más alto.

No ha tenido un problema con no-*static clases interiores -- no pienso aquellos
son siempre una filtración de memoria, él todo depende en el *lifespan duración de los
casos de objeto interiores.

Pienso *MAT es una herramienta grande para *tracking abajo material. Soy siempre prudente de forzar
GC en *DDMS #unos cuantos tiempo (control *logcat producción, hasta que el GC recoge,
básicamente, nada). Esto hace el cuadro mucho más claro.

En *MAT, yo normalmente inicio por mirar en el objeto *histogram, y aplicando
filtros por mi nombre de paquete o una clase específica.

-- *K

2014-09-18 1:35 GMT+04:00 Nathan <nathan.d.mellor@xxxxxxxxx>:

> Tener que *WeakReferences impedir colección de basura? Pensé que eran débil
> porque no impidieron colección de basura.
>
> Estoy viendo que algunos del *Android las clases están aguantando *static
> colecciones de material. No puedo ver donde estoy causando que *behavior, pero mantengo probar.
>
> De hecho, algunos de los artículos en este tema sugieren reemplazar vuestras
> clases interiores anónimas con nombrado, *static clases interiores que haber
> *WeakReferences a la actividad exterior. hay cuarenta de aquellas clases
> interiores, con todo el *clicklisteners y *whatnot. Es bastante un poco de *turmoil
> para cambiarles todo, pero puedo hacer aquello.
>
> Todo en todo, cuando mostrado aquí, estas cosas son a menudo oscuro.
> Me tomó semanas a pista abajo una filtración de memoria causada por *Google *Analytics
> antes de que podría liberar mi primer *app.  Creo *MAT me ayudó encuentra la evidencia
> crucial.
>
> Tiene el resto de ti encontrado que siguiendo los vínculos, árboles, informes, y *histograms
> en Memoria *Analyzer es útil? Parece gusta allí *ought para
> ser algunas pistas en allí, pero estoy consiguiendo mayoritariamente ventajas falsas.
>
> *Otherwise Estoy utilizando *Treking método. Imposibilitando bits de funcionalidad a la vez.
> 
>
> Nathan
>
>
> En martes, septiembre 16, 2014 5:56:48 SOY *UTC-7, Calles De *Boston escribió:
>>
>> tuve un asunto similar una vez y yo *tracked lo abajo a la Vista#*setTag(*int
>> llave, Objeto *tag) método.
>> En mi código, *setTag fue llamado con un *tag el valor que es un holding
>> de objeto/*referencing un caso que tuvo niños *referring a niños de la
>> Vista en el cual este *setTag fue llamado (*tag era un '*ViewHolder'
>> caso).
>>
>> Versiones seguras de *Android implementa *setTag utilizando un **static *mapa de *WeakRereferences.
>> Esto causó una Vista a nunca conseguir la basura recogida, desde
>> el *tag aguantaría referencias a sus niños *whose padres  entonces
>> punto (completamente arriba de) a aquella Vista otra vez. Y si una Vista no consigue
>> la basura recogida, su Contexto (*i.*e. Actividad) nunca conseguiría la basura
>> recogió.
>>
>> Mirada si hay cualquier cosa aguantando encima a vuestra Actividad por la virtud de otros
>> casos que son aguantado #por *incorrect uso de *WeakReferences.
>>
>>
>> En miércoles, septiembre 10, 2014 12:00:36 SOY *UTC-4, Nathan escribió:
>>>
>>> soy *fairly seguro he sido capaz de utilizar el *eclipse herramientas antes de que a pista
>>> abajo filtraciones de memoria - yo incluso encontrado uno en *Google *Analytics.
>>>
>>> Pero puedo no para la vida de mí imagina fuera.
>>>
>>> He descubierto que hay dos casos de Actividad *B en memoria
>>> cuándo la actividad es cerrada. Puedo ver que con sé
>>>
>>> bastante para saber que aquello es mal.
>>>
>>> Pero lo que no puedo ver es POR QUÉ. Por qué es que actividad estúpida todavía en
>>> memoria dos veces?
>>>
>>> Parezco para recordar que yo bien clic en algo y escoger Fusionar Camino
>>> a Raíces de GC.
>>>
>>> Entonces consigo algo así.
>>>
>>>
>>> Nombre de clase
>>> | *Ref. Los Objetos | Superficiales *Heap | *Ref. Superficial *Heap | Retuvo *Heap
>>> ------------------------------------------------------------
>>> ------------------------------------------------------------
>>> -------------------------------------------
>>> *com.*android.Interno.Política.*impl.*PhoneLayoutInflater @ 0*x42*d2*b0*d8
>>> *Unknown                        |            1 |           40
>>> |               536 |            64
>>> '- *mPrivateFactory, *mContext *MyActivity @ 0*x42*d28230|            1
>>> |          536 |               536 |       127,336
>>> clase *com.*android.Interno.*os.*ZygoteInit @ 0*x41#uno21una18 Clase
>>> de Sistema                               |            1 |          120
>>> |               536 |         1,000
>>> '- *mResources *android.Contenido.*res.Recursos @
>>> 0*x41*aa7108                                         |            1
>>> |          112 |               536 |         8,512
>>>    '- *mContext *android.*app.*ContextImpl @ 0*x43009398
>>> |            1 |          128 |               536 |        10,400
>>>       '- *mOuterContext *MyActivity @ 0*x42*d4*f008      |            1
>>> |          536 |               536 |         3,864
>>> ------------------------------------------------------------
>>> ------------------------------------------------------------
>>> -------------------------------------------
>>>
>>> Bien que *PhoneLayoutInflater no tendría que ser aguantando encima a aquel contexto de una
>>> actividad cerrada, pero no pienso controlo aquello.
>>> Y sin duda que *ZygoteInit la cosa no tendría que ser aguantando un contexto en
>>> un *static manera, pero no controlo que cualquiera.
>>>
>>> Cualesquier consejos en encontrar las causas mejores?
>>>
>>> Nathan
>>>
>>>
>>> Nathan
>>>
>>  --
> recibiste este mensaje porque eres *subscribed al *Google
> Grupos "*Android *Developers" grupo.
> A correo a este grupo, envía *email a *android-developers@xxxxxxxxxxxxxxxx
> A *unsubscribe de este grupo, envía *email a *android-*developers+unsubscribe@xxxxxxxxxxxxxxxx
> 
> Puesto que más opciones, visita este grupo en
> *http://grupos.*google.*com/Grupo/*android-*developers?*hl=*en
> ---
> Recibiste este mensaje porque eres *subscribed al *Google Grupos
> "*Android *Developers" grupo.
> A *unsubscribe de este grupo y la parón que recibe *emails de él, enviar un
> *email a *android-*developers+unsubscribe@xxxxxxxxxxxxxxxx.
> Puesto que más opciones, visita *https://grupos.*google.*com/*d/*optout.
>

-- 
Recibiste este mensaje porque eres *subscribed al *Google
Grupos "*Android *Developers" grupo.
A correo a este grupo, envía *email a *android-developers@xxxxxxxxxxxxxxxx
A *unsubscribe de este grupo, envía *email a *android-*developers+unsubscribe@xxxxxxxxxxxxxxxx

Puesto que más opciones, visita este grupo en
*http://grupos.*google.*com/Grupo/*android-*developers?*hl=*en
--- 
Recibiste este mensaje porque eres *subscribed al *Google Grupos "*Android *Developers" grupo.
A *unsubscribe de este grupo y la parón que recibe *emails de él, enviar un *email a *android-*developers+unsubscribe@xxxxxxxxxxxxxxxx.
Puesto que más opciones, visita *https://grupos.*google.*com/*d/*optout.
In my experience, WeakReferences are collected quite aggressively by
Android 2.3 and higher.

Haven't had a problem with non-static inner classes -- I don't think those
are always a memory leak, it all depends on the lifespan duration of the
inner object instances.

I think MAT is a great tool for tracking down stuff. I'm always careful to
force GC in DDMS a few times (monitoring logcat output, until GC collects,
basically, nothing). This makes the picture a lot clearer.

In MAT, I usually start by looking at the object histogram, and applying
filters by my package name or a specific class.

-- K

2014-09-18 1:35 GMT+04:00 Nathan <nathan.d.mellor@xxxxxxxxx>:

> Should WeakReferences prevent garbage collection? I thought they were weak
> because they didn't prevent garbage collection.
>
> I am seeing that some of the Android classes are holding static
> collections of stuff. I can't see where I am causing that behavior, but I
> keep trying.
>
> In fact, some of the articles on this topic suggest replacing your
> anonymous inner classes with named, static inner classes that have
> WeakReferences to the outer activity. There are forty of those inner
> classes, with all the clicklisteners and whatnot. It is quite a bit of
> turmoil to change them all, but I may do that.
>
> All in all, as shown here, these things are often obscure.
> It took me weeks to track down a memory leak caused by Google Analytics
> before I could release my first app.  I believe MAT helped me find the
> crucial evidence.
>
> Have the rest of you found that following the links, trees, reports, and
> histograms in Memory Analyzer are helpful? it seems like there ought to be
> some clues in there, but I am getting mostly false leads.
>
> Otherwise I am using Treking's method. Disabling bits of functionality at
> a time.
>
> Nathan
>
>
> On Tuesday, September 16, 2014 5:56:48 AM UTC-7, Streets Of Boston wrote:
>>
>> I had a similar issue once and I tracked it down to the View#setTag(int
>> key, Object tag) method.
>> In my code, setTag was called with a tag value being an object
>> holding/referencing an instance that had children referring to children of
>> the View on which this setTag was called (tag was a 'ViewHolder'
>> instance).
>>
>> Certain versions of Android implement setTag using a *static *map of
>> WeakRereferences. This caused a View to never get garbage collected, since
>> the tag would hold references to its children whose parents would then
>> point (all the way up) to that View again. And if a View doesn't get
>> garbage collected, its Context (i.e. Activity) would never get garbage
>> collected.
>>
>> Look if there is anything holding on to your Activity by the virtue of
>> other instances being held through incorrect usage of WeakReferences.
>>
>>
>> On Wednesday, September 10, 2014 12:00:36 AM UTC-4, Nathan wrote:
>>>
>>> I'm fairly sure I have been able to use the eclipse tools before to
>>> track down memory leaks - I even found one in Google Analytics.
>>>
>>> But I can't for the life of me figure out.
>>>
>>> I have found out that there are two instances of Activity B in memory
>>> when the activity is closed. I can see that with
>>>
>>> I know enough to know that that is bad.
>>>
>>> But what I cannot see is WHY. Why is that stupid activity still in
>>> memory twice?
>>>
>>> I seem to remember that I right click on something and choose Merge Path
>>> to GC Roots.
>>>
>>> Then I get something like this.
>>>
>>>
>>> Class Name
>>> | Ref. Objects | Shallow Heap | Ref. Shallow Heap | Retained Heap
>>> ------------------------------------------------------------
>>> ------------------------------------------------------------
>>> -------------------------------------------
>>> com.android.internal.policy.impl.PhoneLayoutInflater @ 0x42d2b0d8
>>> Unknown                        |            1 |           40
>>> |               536 |            64
>>> '- mPrivateFactory, mContext MyActivity @ 0x42d28230|            1
>>> |          536 |               536 |       127,336
>>> class com.android.internal.os.ZygoteInit @ 0x41a21a18 System
>>> Class                               |            1 |          120
>>> |               536 |         1,000
>>> '- mResources android.content.res.Resources @
>>> 0x41aa7108                                         |            1
>>> |          112 |               536 |         8,512
>>>    '- mContext android.app.ContextImpl @ 0x43009398
>>> |            1 |          128 |               536 |        10,400
>>>       '- mOuterContext MyActivity @ 0x42d4f008      |            1
>>> |          536 |               536 |         3,864
>>> ------------------------------------------------------------
>>> ------------------------------------------------------------
>>> -------------------------------------------
>>>
>>> Well that PhoneLayoutInflater shouldn't be holding on to that context of
>>> a closed activity, but I don't think I control that.
>>> And definitely that ZygoteInit thing shouldn't be holding a context in a
>>> static way, but I don't control that either.
>>>
>>> Any tips on finding the causes better?
>>>
>>> Nathan
>>>
>>>
>>> Nathan
>>>
>>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@xxxxxxxxxxxxxxxx
> To unsubscribe from this group, send email to
> android-developers+unsubscribe@xxxxxxxxxxxxxxxx
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Android Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to android-developers+unsubscribe@xxxxxxxxxxxxxxxx.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@xxxxxxxxxxxxxxxx
To unsubscribe from this group, send email to
android-developers+unsubscribe@xxxxxxxxxxxxxxxx
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@xxxxxxxxxxxxxxxx.
For more options, visit https://groups.google.com/d/optout.
<Anterior por Tema] Tema Actual [Siguiente por Tema>