2012-06-08 21 views
9

Estoy usando un visor para cargar alrededor de 50 vistas web ... Todas las vistas web se cargan en los assests y cada weview tiene una página HTML que está accediendo a alrededor de 70 imágenes cada ... Al deslizar, mi la aplicación se cuelga después de alrededor de 30 páginas, podría ser debido a que las vistas de la web aún mantienen su referencia a las imágenes en la carpeta de assests ... ¿Hay alguna forma de liberar las vistas de la web que el Viewpager no está usando en ese momento en particular?Viewpager Problema de memoria Webview

awesomePager.setAdapter(new AwesomePagerAdapter(this, webviewdata)); 

Detalles:

Android WebView Memory Leak when loading html file from Assets 
Failed adding to JNI local ref table (has 512 entries) 
"Thread-375" prio=5 tid=15 RUNNABLE 

mientras se carga dinámicamente en vista web ViewPager

Logcat: enter image description here

Respuesta

1

Trate de bajar bitmap.Most del mapa de bits de tiempo es una razón principal por la que Obtiene el problema de la memoria. También aprenda sobre cómo reciclar bitmaps. El siguiente fragmento lo ayudará.

BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inJustDecodeBounds = true; 
    BitmapFactory.decodeFile(filename, options); 
     options.inJustDecodeBounds = false; 
     options.inSampleSize = 2; 

     bitmap = BitmapFactory.decodeFile(filename, options); 
     if (bitmap != null && exact) { 
      bitmap = Bitmap.createScaledBitmap(bitmap, width, height, false); 
     } 

También asegúrese de anular el siguiente método.

@Override 
public void destroyItem(View collection, int position, Object view) { 
    ((ViewPager) collection).removeView((TextView) view); 
} 

O puede crear una función de bajar de mapa de bits

private byte[] resizeImage(byte[] input) { 

    if (input == null) { 
     return null; 
    } 

    Bitmap bitmapOrg = BitmapFactory.decodeByteArray(input, 0, input.length); 

    if (bitmapOrg == null) { 
     return null; 
    } 

    int height = bitmapOrg.getHeight(); 
    int width = bitmapOrg.getWidth(); 
    int newHeight = 250; 

    float scaleHeight = ((float) newHeight)/height; 

    // creates matrix for the manipulation 
    Matrix matrix = new Matrix(); 
    // resize the bit map 
    matrix.postScale(scaleHeight, scaleHeight); 

    // recreate the new Bitmap 
    Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, 
      width, height, matrix, true); 

    bitmapOrg.recycle(); 

    ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
    resizedBitmap.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, bos);    

    resizedBitmap.recycle(); 

    return bos.toByteArray();    
}  
+1

gracias por su solvencia, pero la pregunta anterior es para la vista web !!! –

+1

@Vipul Sí, he anulado destruirItem, aún no tengo suerte. – Kiran

0

La vista Web trabaja con el JNI y esto sólo puede contener 512 referencias locales, intente cargar su contenido directamente desde la web y el problema no deben no ocurre

Aparece este problema cuando invalido shouldInterceptRequest(WebView view, String url) en webviewclient y proporciono referencias locales de mi propio mecanismo de almacenamiento en caché.

Esto podría ser un error en la propia vista web. Al menos no es cómo debería comportarse si me preguntas.

0

Configuración del tipo de capa de vista web para el software.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 
    webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 
} 

Pero ahora pierde aceleración de hardware y su vista web puede ralentizarse.