IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

bitmap.recycle() fait planter le projet


Sujet :

Android

  1. #1
    Membre à l'essai
    Profil pro
    Intégrateur Web
    Inscrit en
    Octobre 2012
    Messages
    30
    Détails du profil
    Informations personnelles :
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Intégrateur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Octobre 2012
    Messages : 30
    Points : 20
    Points
    20
    Par défaut bitmap.recycle() fait planter le projet
    Bonjour,

    J'ai essayé d'utiliser le source du projet DVP_Gallery.zip sur
    http://mickael-lt.developpez.com/tut...rie-connectee/

    Ce proc fonctionne avec des images de petite taille et j'essaie de le faire fonctionner avec de grandes images > 1 Mo.

    Voici mon source :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    package com.dvp.android.gallery;
     
    import java.io.BufferedInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
    import java.nio.ByteBuffer;
    import java.nio.ByteOrder;
    import java.nio.IntBuffer;
    import java.util.ArrayList;
     
    import android.app.Activity;
    import android.app.ProgressDialog;
    import android.content.Context;
    import android.content.res.TypedArray;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.drawable.Drawable;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.os.Environment;
    import android.util.Log;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.AdapterView;
    import android.widget.BaseAdapter;
    import android.widget.Gallery;
    import android.widget.ImageView;
    import android.widget.AdapterView.OnItemClickListener;
     
    /**
     * @author Mickaël Le Trocquer
     */
    public class DVPGallery extends Activity {
     
    	//Adresse où se trouve l'ensemble des images gif (numérotées de 1 à 21).
    	private final static String SERVER_IM = "http://www.e-kom.fr/p_public/test12789go/uploads/";
     
    	// GUI
    	private Gallery gallery;
    	private ImageView imgView;
     
    	//Data
    	private ArrayList<URL> mListImages;
    	private Drawable mNoImage;
     
    	/** Called when the activity is first created. */
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.main);
     
    		//Récupération d'une image par défaut à afficher en cas d'erreur ou de liste vide
    		mNoImage = this.getResources().getDrawable(R.drawable.ic_launcher);
     
    		//Construction des URL pour les images
    //		mListImages = buildListImages();
    	        new AT_buildListImages().execute("");
     
    	        Runtime.getRuntime().gc();
    	}
     
     
    	/**
             * Permet de construire la liste des urls pour les images
             * @return
             */
    //	private ArrayList<URL> buildListImages() {
    	public class AT_buildListImages extends AsyncTask<String, Void, Void> {
     
    	        ProgressDialog Dialog = new ProgressDialog(DVPGallery.this);
     
    	        protected void onPreExecute() {
    //    		super.onPreExecute();
     
    	            Dialog.setMessage("Loading images...");
            	    Dialog.show();
    	        }
     
                @Override
           	    protected Void doInBackground(String... param) {
        		int nbTotalImage = 2;
    //		int nbTotalImage = files.length;
        		ArrayList<URL> listFic = new ArrayList<URL>();
        		for(int i = 1; i <= nbTotalImage; i++) {
        			try {
        				listFic.add(new URL(SERVER_IM + "/" + i + ".gif"));
        			} catch (MalformedURLException e) {
        				Log.e("DVP Gallery", "Erreur format URL : " + SERVER_IM + "/" + i + ".gif");
        				e.printStackTrace();
        			}
        		}
     
    	        Runtime.getRuntime().gc();
        		mListImages = listFic;
        		return null;
            	}
     
                protected void onPostExecute(Void unused) {
    //            	super.onPostExecute(unused);
     
                	connect_1st();
     
                    // Close progress dialog
                    Dialog.dismiss();
                }
        	}
     
    	public Void connect_1st() {
     
    		//Récupération du composant affichant l'image en grand
    		imgView = (ImageView)findViewById(R.id.imageview);
     
    		//On lui met une image par défaut (la premiere de la liste ou à défaut l'image d'erreur)
    		if (mListImages.size() <= 0) {
    			imgView.setImageDrawable(mNoImage); 
    		} else {
    			setImage(imgView, mListImages.get(0));
    		}
    		//Récupération du composant affichant la liste des vignettes
    		gallery = (Gallery) findViewById(R.id.gallery);
    		//On lui donne notre adapter qui s'occupéra de l'alimenter en vignette
    		gallery.setAdapter(new AddImgAdp(this));
    		//Espacement entre les vignette
    		gallery.setSpacing(10);
     
    		//Lors d'un clic sur une des vignettes, on affiche l'image correspondante en grand
    		gallery.setOnItemClickListener(new OnItemClickListener() {
    			public void onItemClick(AdapterView parent, View v, int position, long id) {			
    				setImage(imgView, mListImages.get(position));
    			}
    		});
     
                Runtime.getRuntime().gc();
    	    return null;
    	}
     
     
    	/**
             * Notre adapter qui gère la liste des vignettes
             * @author Mickaël Le Trocquer
             */
    	public class AddImgAdp extends BaseAdapter {
    		int GalItemBg;
    		private Context cont;
     
    		public AddImgAdp(Context c) {
    			cont = c;
    			TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme);
    			GalItemBg = typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
    			typArray.recycle();
    		}
     
    		public int getCount() {
    			return mListImages.size();
    		}
     
    		public Object getItem(int position) {
    			return position;
    		}
     
    		public long getItemId(int position) {
    			return position;
    		}
     
    		public View getView(final int position, View convertView, ViewGroup parent) {
    			ImageView imgView = null;
    			//Récyclage du composant
    			if (convertView == null) {
    				imgView = new ImageView(cont);
    			} else {
    				imgView = (ImageView)convertView;
    			}
    			//On affecte notre image à la vignette
    			if (mListImages.size() <= 0) {
    				imgView.setImageDrawable(mNoImage); 
    			} else {
    				setImage(imgView, mListImages.get(position));
    			}
    			//On défini la taille de l'image
    			imgView.setLayoutParams(new Gallery.LayoutParams(150, 150));
    			imgView.setScaleType(ImageView.ScaleType.FIT_XY);
    			//On fixe un arrière plan plus sympa
    			imgView.setBackgroundResource(GalItemBg);
     
    			return imgView;
    		}
    	}
     
     
    	/**
             * Méthode permettant de télécharger une image depuis une URL et de l'affecter à un composant de type ImageView
             * @param aView
             * @param aURL
             */
    	public void setImage(ImageView aView, URL aURL) {
    		try {
    			URLConnection conn = aURL.openConnection();
    			conn.connect();
    			InputStream is = conn.getInputStream();
     
    			// Bufferisation pour le téléchargement 
    			BufferedInputStream bis = new BufferedInputStream(is);
     
    	                Runtime.getRuntime().gc();
    			// Création de l'image depuis le flux des données entrant
    			Bitmap bm = BitmapFactory.decodeStream(bis);
    			int dstWidth = 150, dstHeight = 150;
    			bm.createScaledBitmap(bm, dstWidth, dstHeight, true);
    			bis.close();
    			is.close();
     
    			// Fixe l'image sur le composant ImageView
    			aView.setImageBitmap(bm);
    //			if (bm != null) bm.recycle();
     
    		} catch (IOException e) {
    			aView.setImageDrawable(mNoImage);
    			Log.e("DVP Gallery", "Erreur téléchargement image URL : " + aURL.toString());
    			e.printStackTrace();
    		} 
    	}
    }
    J'ai mis le buildListImages() en asynctask AT_buildListImages(), qui fonctionne,

    j'ai réduit la taille de nbTotalImage = files.length; à 2 seulement, sur 1 image il fonctionne,

    j'ai mis un scale sur le seul bitmap du proc par bm.createScaledBitmap(bm, dstWidth, dstHeight, true) ; ce scale fonctionne seulement si la première image est grande mais les autres doivent rester petites,

    et j'ai essayé de mettre un recycle() après le aView.setImageBitmap(bm); if (bm != null) bm.recycle(); qui fait planter le projet. Je ne comprends pas pourquoi le bm.recycle(); plante.

    Je ne sais plus quoi faire pour utiliser des grandes images. Je ne suis pas un spécialiste des problèmes de mémoire. Des idées please ?

    Daniel

  2. #2
    Membre extrêmement actif
    Profil pro
    Développeur
    Inscrit en
    Mars 2012
    Messages
    1 969
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Mars 2012
    Messages : 1 969
    Points : 3 375
    Points
    3 375
    Par défaut
    Ne serait-ce pas lié à tes appels au gc?

    Peut-être que le système a déjà effacé certains objets liés au bitmap (image, file...).

    Essaye en retirant tous ces appels et efface les par code.
    Ensuite tu appelles le gc à la rescousse lorque tu quittes ta procédure.
    Si la réponse vous a aidé, pensez à cliquer sur +1

  3. #3
    Modérateur
    Avatar de Hizin
    Homme Profil pro
    Développeur mobile
    Inscrit en
    Février 2010
    Messages
    2 180
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France

    Informations professionnelles :
    Activité : Développeur mobile

    Informations forums :
    Inscription : Février 2010
    Messages : 2 180
    Points : 5 072
    Points
    5 072
    Par défaut
    Sachant que les appels explicite au garbage collector sont à proscrire la plupart du temps en prime.

    À priori, tu dis planter, donc quelle est l'erreur (stacktrace complète) s'il te plaît ?

    J'imagine un message disant "je ne peux pas appeler recycle sur une vue déjà recyclée". Dans ce cas-là, tes images sont recyclées plusieurs fois. La méthode Bitmap#isRecycled peut t'aider dans ce cas.
    C'est Android, PAS Androïd, ou Androïde didiou !
    Le premier est un OS, le second est la mauvaise orthographe du troisième, un mot français désignant un robot à forme humaine.

    Membre du comité contre la phrase "ça marche PAS" en titre et/ou explication de problème.

    N'oubliez pas de consulter les FAQ Android et les cours et tutoriels Android

  4. #4
    Membre extrêmement actif
    Profil pro
    Développeur
    Inscrit en
    Mars 2012
    Messages
    1 969
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Mars 2012
    Messages : 1 969
    Points : 3 375
    Points
    3 375
    Par défaut
    Il y a également une méthode "spéciale" qui permet de charger l'image en question et de ne pas la garder, en libérant rapidement la mémoire.
    C'est normalement géré par le système.
    Il faudrait retrouver cette méthode...
    Si la réponse vous a aidé, pensez à cliquer sur +1

  5. #5
    Membre à l'essai
    Profil pro
    Intégrateur Web
    Inscrit en
    Octobre 2012
    Messages
    30
    Détails du profil
    Informations personnelles :
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Intégrateur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Octobre 2012
    Messages : 30
    Points : 20
    Points
    20
    Par défaut
    Merci pour vos réponses.

    Pour hotcryx, en fait j'ai retiré tous les appels au gc, et ça ne change rien du tout. Pour la méthode "spéciale" je vais regarder.


    Merci à Hizin : j'ai regardé le isRecycled, il est toujours faux si je n'utilise pas Recycle().

    J'ai lancé le prog sans Recycle() et sans plantage pour 11 images petites 77ko, et j'ai ceci :

    08-11 12:07:13.978: E/Trace(6071): error opening trace file: No such file or directory (2)
    08-11 12:07:14.778: D/dalvikvm(6071): GC_FOR_ALLOC freed 57K, 2% free 6280K/6407K, paused 80ms, total 81ms
    08-11 12:07:14.808: I/dalvikvm-heap(6071): Grow heap (frag case) to 7.051MB for 932416-byte allocation
    08-11 12:07:14.848: D/dalvikvm(6071): GC_CONCURRENT freed 4K, 3% free 7187K/7367K, paused 15ms+5ms, total 43ms
    08-11 12:07:14.848: D/dalvikvm(6071): WAIT_FOR_CONCURRENT_GC blocked 30ms
    08-11 12:07:14.988: D/dalvikvm(6071): WAIT_FOR_CONCURRENT_GC blocked 1ms
    08-11 12:07:15.038: D/dalvikvm(6071): GC_EXPLICIT freed 40K, 3% free 7155K/7367K, paused 3ms+7ms, total 48ms
    08-11 12:07:15.148: D/dalvikvm(6071): GC_FOR_ALLOC freed 7K, 3% free 7183K/7367K, paused 33ms, total 33ms
    08-11 12:07:15.158: I/dalvikvm-heap(6071): Grow heap (frag case) to 7.934MB for 932416-byte allocation
    08-11 12:07:15.198: D/dalvikvm(6071): GC_CONCURRENT freed 0K, 3% free 8093K/8327K, paused 15ms+3ms, total 45ms
    08-11 12:07:15.198: D/dalvikvm(6071): WAIT_FOR_CONCURRENT_GC blocked 31ms
    08-11 12:07:15.668: D/dalvikvm(6071): GC_FOR_ALLOC freed 36K, 2% free 8244K/8391K, paused 88ms, total 91ms
    08-11 12:07:15.688: I/dalvikvm-heap(6071): Grow heap (frag case) to 8.971MB for 932416-byte allocation
    08-11 12:07:15.758: D/dalvikvm(6071): GC_CONCURRENT freed <1K, 3% free 9154K/9351K, paused 17ms+8ms, total 74ms
    08-11 12:07:15.758: D/dalvikvm(6071): WAIT_FOR_CONCURRENT_GC blocked 27ms
    08-11 12:07:16.088: D/dalvikvm(6071): GC_FOR_ALLOC freed 35K, 3% free 9156K/9351K, paused 23ms, total 23ms
    08-11 12:07:16.088: I/dalvikvm-heap(6071): Grow heap (frag case) to 9.862MB for 932416-byte allocation
    08-11 12:07:16.118: D/dalvikvm(6071): GC_FOR_ALLOC freed 0K, 3% free 10067K/10311K, paused 23ms, total 23ms

    puis j'ai mis la ligne if (bm != null && ! bm.isRecycled) bm.Recycle();, à la fin du setimage(), sans toucher aux images, et le plantage donne ceci :

    08-11 12:30:20.317: E/Trace(8100): error opening trace file: No such file or directory (2)
    08-11 12:30:21.287: D/dalvikvm(8100): GC_FOR_ALLOC freed 86K, 2% free 6280K/6407K, paused 101ms, total 102ms
    08-11 12:30:21.297: I/dalvikvm-heap(8100): Grow heap (frag case) to 7.051MB for 932416-byte allocation
    08-11 12:30:21.357: D/dalvikvm(8100): GC_CONCURRENT freed 4K, 3% free 7187K/7367K, paused 23ms+4ms, total 66ms
    08-11 12:30:21.357: D/dalvikvm(8100): WAIT_FOR_CONCURRENT_GC blocked 43ms
    08-11 12:30:21.447: D/dalvikvm(8100): WAIT_FOR_CONCURRENT_GC blocked 0ms
    08-11 12:30:21.547: D/dalvikvm(8100): GC_EXPLICIT freed 40K, 3% free 7178K/7367K, paused 2ms+10ms, total 94ms
    08-11 12:30:21.647: D/dalvikvm(8100): GC_FOR_ALLOC freed 7K, 3% free 7205K/7367K, paused 31ms, total 31ms
    08-11 12:30:21.657: I/dalvikvm-heap(8100): Grow heap (frag case) to 7.957MB for 932416-byte allocation
    08-11 12:30:21.697: D/dalvikvm(8100): GC_CONCURRENT freed 0K, 3% free 8116K/8327K, paused 14ms+3ms, total 41ms
    08-11 12:30:21.697: D/dalvikvm(8100): WAIT_FOR_CONCURRENT_GC blocked 27ms
    08-11 12:30:22.077: D/dalvikvm(8100): GC_FOR_ALLOC freed 37K, 2% free 8274K/8391K, paused 29ms, total 29ms
    08-11 12:30:22.077: I/dalvikvm-heap(8100): Grow heap (frag case) to 9.000MB for 932416-byte allocation
    08-11 12:30:22.117: D/dalvikvm(8100): GC_CONCURRENT freed 1K, 2% free 9184K/9351K, paused 13ms+3ms, total 38ms
    08-11 12:30:22.117: D/dalvikvm(8100): WAIT_FOR_CONCURRENT_GC blocked 20ms
    08-11 12:30:23.097: D/dalvikvm(8100): GC_CONCURRENT freed 977K, 12% free 9175K/10311K, paused 13ms+16ms, total 73ms
    08-11 12:30:23.107: D/AndroidRuntime(8100): Shutting down VM
    08-11 12:30:23.107: W/dalvikvm(8100): threadid=1: thread exiting with uncaught exception (group=0x40c6e300)
    08-11 12:30:23.137: E/AndroidRuntime(8100): FATAL EXCEPTION: main
    08-11 12:30:23.137: E/AndroidRuntime(8100): java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@4125c998
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.graphics.Canvas.throwIfRecycled(Canvas.java:1026)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.graphics.Canvas.drawBitmap(Canvas.java:1127)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:393)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.widget.ImageView.onDraw(ImageView.java:979)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.View.draw(View.java:13458)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.View.draw(View.java:13342)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2806)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.View.draw(View.java:13461)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.View.draw(View.java:13342)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.View.draw(View.java:13340)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.View.draw(View.java:13340)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.View.draw(View.java:13340)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.ViewGroup.drawChild(ViewGroup.java:2929)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2799)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.View.draw(View.java:13461)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.widget.FrameLayout.draw(FrameLayout.java:467)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2183)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2256)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2151)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2019)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1830)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4213)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.Choreographer.doFrame(Choreographer.java:525)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.os.Handler.handleCallback(Handler.java:615)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.os.Handler.dispatchMessage(Handler.java:92)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.os.Looper.loop(Looper.java:137)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at android.app.ActivityThread.main(ActivityThread.java:4745)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at java.lang.reflect.Method.invokeNative(Native Method)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at java.lang.reflect.Method.invoke(Method.java:511)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    08-11 12:30:23.137: E/AndroidRuntime(8100): at dalvik.system.NativeStart.main(Native Method)
    08-11 12:30:24.757: I/Process(8100): Sending signal. PID: 8100 SIG: 9

    c'est bien en rapport avec le bitmap recycled.

    Un truc m'a échappé !

  6. #6
    Membre à l'essai
    Profil pro
    Intégrateur Web
    Inscrit en
    Octobre 2012
    Messages
    30
    Détails du profil
    Informations personnelles :
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Intégrateur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Octobre 2012
    Messages : 30
    Points : 20
    Points
    20
    Par défaut
    Je complète mon test.

    Sans le recycle() et avec la première image > 1Mo ça marche.

    Si je mets deux images > 1 Mo voilà du boudin :

    08-11 18:28:34.859: E/Trace(2162): error opening trace file: No such file or directory (2)
    08-11 18:28:35.699: D/dalvikvm(2162): GC_FOR_ALLOC freed 93K, 3% free 6285K/6471K, paused 72ms, total 75ms
    08-11 18:28:35.869: I/dalvikvm-heap(2162): Grow heap (frag case) to 24.916MB for 19660816-byte allocation
    08-11 18:28:35.909: D/dalvikvm(2162): GC_FOR_ALLOC freed 4K, 1% free 25481K/25735K, paused 38ms, total 38ms
    08-11 18:28:35.979: D/dalvikvm(2162): GC_CONCURRENT freed <1K, 1% free 25481K/25735K, paused 17ms+8ms, total 73ms
    08-11 18:28:42.919: D/dalvikvm(2162): WAIT_FOR_CONCURRENT_GC blocked 0ms
    08-11 18:28:42.959: D/dalvikvm(2162): GC_EXPLICIT freed 60K, 2% free 25445K/25735K, paused 3ms+5ms, total 41ms
    08-11 18:28:42.959: I/Choreographer(2162): Skipped 566 frames! The application may be doing too much work on its main thread.
    08-11 18:28:43.119: D/dalvikvm(2162): GC_FOR_ALLOC freed 7K, 2% free 25474K/25735K, paused 28ms, total 28ms
    08-11 18:28:43.219: I/dalvikvm-heap(2162): Grow heap (frag case) to 43.657MB for 19660816-byte allocation
    08-11 18:28:43.269: D/dalvikvm(2162): GC_CONCURRENT freed 0K, 1% free 44674K/44999K, paused 14ms+6ms, total 45ms
    08-11 18:28:43.269: D/dalvikvm(2162): WAIT_FOR_CONCURRENT_GC blocked 22ms
    08-11 18:28:50.819: D/dalvikvm(2162): GC_FOR_ALLOC freed 57K, 1% free 44826K/44999K, paused 31ms, total 32ms
    08-11 18:28:50.819: I/dalvikvm-heap(2162): Forcing collection of SoftReferences for 19660816-byte allocation
    08-11 18:28:50.869: D/dalvikvm(2162): GC_BEFORE_OOM freed <1K, 1% free 44825K/44999K, paused 47ms, total 47ms
    08-11 18:28:50.869: E/dalvikvm-heap(2162): Out of memory on a 19660816-byte allocation.
    08-11 18:28:50.869: I/dalvikvm(2162): "main" prio=5 tid=1 RUNNABLE
    08-11 18:28:50.869: I/dalvikvm(2162): | group="main" sCount=0 dsCount=0 obj=0x4145a568 self=0x4144aa40
    08-11 18:28:50.869: I/dalvikvm(2162): | sysTid=2162 nice=0 sched=0/0 cgrp=[no-cpu-subsys] handle=1075086896
    08-11 18:28:50.869: I/dalvikvm(2162): | schedstat=( 2072074028 1015983689 6617 ) utm=165 stm=42 core=0
    08-11 18:28:50.869: I/dalvikvm(2162): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
    08-11 18:28:50.869: I/dalvikvm(2162): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:527)
    08-11 18:28:50.869: I/dalvikvm(2162): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:599)
    08-11 18:28:50.869: I/dalvikvm(2162): at com.dvp.android.gallery.DVPGallery.setImage(DVPGallery.java:222)
    08-11 18:28:50.869: I/dalvikvm(2162): at com.dvp.android.gallery.DVPGallery$AddImgAdp.getView(DVPGallery.java:189)
    08-11 18:28:50.869: I/dalvikvm(2162): at android.widget.Gallery.makeAndAddView(Gallery.java:849)
    08-11 18:28:50.869: I/dalvikvm(2162): at android.widget.Gallery.fillToGalleryRightLtr(Gallery.java:803)
    08-11 18:28:50.869: I/dalvikvm(2162): at android.widget.Gallery.fillToGalleryRight(Gallery.java:747)
    08-11 18:28:50.869: I/dalvikvm(2162): at android.widget.Gallery.layout(Gallery.java:656)
    08-11 18:28:50.869: I/dalvikvm(2162): at android.widget.Gallery.onLayout(Gallery.java:351)
    08-11 18:28:50.889: I/dalvikvm(2162): at android.view.View.layout(View.java:13754)
    08-11 18:28:50.889: I/dalvikvm(2162): at android.view.ViewGroup.layout(ViewGroup.java:4362)
    08-11 18:28:50.899: I/dalvikvm(2162): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)
    08-11 18:28:50.899: I/dalvikvm(2162): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1507)
    08-11 18:28:50.899: I/dalvikvm(2162): at android.widget.LinearLayout.onLayout(LinearLayout.java:1420)
    08-11 18:28:50.899: I/dalvikvm(2162): at android.view.View.layout(View.java:13754)
    08-11 18:28:50.899: I/dalvikvm(2162): at android.view.ViewGroup.layout(ViewGroup.java:4362)
    08-11 18:28:50.899: I/dalvikvm(2162): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
    08-11 18:28:50.899: I/dalvikvm(2162): at android.view.View.layout(View.java:13754)
    08-11 18:28:50.899: I/dalvikvm(2162): at android.view.ViewGroup.layout(ViewGroup.java:4362)
    08-11 18:28:50.899: I/dalvikvm(2162): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)
    08-11 18:28:50.899: I/dalvikvm(2162): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1507)
    08-11 18:28:50.899: I/dalvikvm(2162): at android.widget.LinearLayout.onLayout(LinearLayout.java:1420)
    08-11 18:28:50.899: I/dalvikvm(2162): at android.view.View.layout(View.java:13754)
    08-11 18:28:50.899: I/dalvikvm(2162): at android.view.ViewGroup.layout(ViewGroup.java:4362)
    08-11 18:28:50.899: I/dalvikvm(2162): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
    08-11 18:28:50.899: I/dalvikvm(2162): at android.view.View.layout(View.java:13754)
    08-11 18:28:50.899: I/dalvikvm(2162): at android.view.ViewGroup.layout(ViewGroup.java:4362)
    08-11 18:28:50.909: I/dalvikvm(2162): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1866)
    08-11 18:28:50.909: I/dalvikvm(2162): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1687)
    08-11 18:28:50.909: I/dalvikvm(2162): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
    08-11 18:28:50.909: I/dalvikvm(2162): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4213)
    08-11 18:28:50.909: I/dalvikvm(2162): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
    08-11 18:28:50.909: I/dalvikvm(2162): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
    08-11 18:28:50.909: I/dalvikvm(2162): at android.view.Choreographer.doFrame(Choreographer.java:525)
    08-11 18:28:50.909: I/dalvikvm(2162): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
    08-11 18:28:50.909: I/dalvikvm(2162): at android.os.Handler.handleCallback(Handler.java:615)
    08-11 18:28:50.909: I/dalvikvm(2162): at android.os.Handler.dispatchMessage(Handler.java:92)
    08-11 18:28:50.909: I/dalvikvm(2162): at android.os.Looper.loop(Looper.java:137)
    08-11 18:28:50.909: I/dalvikvm(2162): at android.app.ActivityThread.main(ActivityThread.java:4745)
    08-11 18:28:50.909: I/dalvikvm(2162): at java.lang.reflect.Method.invokeNative(Native Method)
    08-11 18:28:50.909: I/dalvikvm(2162): at java.lang.reflect.Method.invoke(Method.java:511)
    08-11 18:28:50.909: I/dalvikvm(2162): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    08-11 18:28:50.909: I/dalvikvm(2162): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    08-11 18:28:50.909: I/dalvikvm(2162): at dalvik.system.NativeStart.main(Native Method)
    08-11 18:28:50.909: D/skia(2162): --- decoder->decode returned false
    08-11 18:28:50.909: D/AndroidRuntime(2162): Shutting down VM
    08-11 18:28:50.909: W/dalvikvm(2162): threadid=1: thread exiting with uncaught exception (group=0x41459300)
    08-11 18:28:50.929: E/AndroidRuntime(2162): FATAL EXCEPTION: main
    08-11 18:28:50.929: E/AndroidRuntime(2162): java.lang.OutOfMemoryError
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:527)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:599)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at com.dvp.android.gallery.DVPGallery.setImage(DVPGallery.java:222)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at com.dvp.android.gallery.DVPGallery$AddImgAdp.getView(DVPGallery.java:189)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.widget.Gallery.makeAndAddView(Gallery.java:849)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.widget.Gallery.fillToGalleryRightLtr(Gallery.java:803)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.widget.Gallery.fillToGalleryRight(Gallery.java:747)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.widget.Gallery.layout(Gallery.java:656)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.widget.Gallery.onLayout(Gallery.java:351)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.view.View.layout(View.java:13754)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.view.ViewGroup.layout(ViewGroup.java:4362)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1507)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.widget.LinearLayout.onLayout(LinearLayout.java:1420)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.view.View.layout(View.java:13754)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.view.ViewGroup.layout(ViewGroup.java:4362)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.view.View.layout(View.java:13754)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.view.ViewGroup.layout(ViewGroup.java:4362)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1507)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.widget.LinearLayout.onLayout(LinearLayout.java:1420)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.view.View.layout(View.java:13754)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.view.ViewGroup.layout(ViewGroup.java:4362)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.view.View.layout(View.java:13754)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.view.ViewGroup.layout(ViewGroup.java:4362)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1866)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1687)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4213)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.view.Choreographer.doFrame(Choreographer.java:525)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.os.Handler.handleCallback(Handler.java:615)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.os.Handler.dispatchMessage(Handler.java:92)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.os.Looper.loop(Looper.java:137)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at android.app.ActivityThread.main(ActivityThread.java:4745)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at java.lang.reflect.Method.invokeNative(Native Method)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at java.lang.reflect.Method.invoke(Method.java:511)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    08-11 18:28:50.929: E/AndroidRuntime(2162): at dalvik.system.NativeStart.main(Native Method)

    -> outofmemory.

    c'est pour ça que j'ai voulu faire un recycle() sur le bitmap.

    Quelle autre solution pour régler ce pb. de outofmemory ? Merci.


  7. #7
    Membre extrêmement actif
    Profil pro
    Développeur
    Inscrit en
    Mars 2012
    Messages
    1 969
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Mars 2012
    Messages : 1 969
    Points : 3 375
    Points
    3 375
    Par défaut
    je vois ceci (en vitesse), mais il faudrait investiguer:

    08-11 18:28:50.909: W/dalvikvm(2162): threadid=1: thread exiting with uncaught exception (group=0x41459300)
    08-11 18:28:50.929: E/AndroidRuntime(2162): FATAL EXCEPTION: main

    Un thread non catché <<<
    Si la réponse vous a aidé, pensez à cliquer sur +1

  8. #8
    Membre à l'essai
    Profil pro
    Intégrateur Web
    Inscrit en
    Octobre 2012
    Messages
    30
    Détails du profil
    Informations personnelles :
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Intégrateur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Octobre 2012
    Messages : 30
    Points : 20
    Points
    20
    Par défaut
    J'ai résolu ce problème en le contournant et en utilisant l'excellente page
    http://developer.android.com/trainin...aps/index.html

    A +

  9. #9
    Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2015
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Doubs (Franche Comté)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Services à domicile

    Informations forums :
    Inscription : Janvier 2015
    Messages : 2
    Points : 3
    Points
    3
    Par défaut A Daniel777
    Bonjour,

    J'ai le meme probleme que toi et je n'arrive pas a me servir du lien que t'as donner pour solution.
    Merci de m'aider encore plus en detail!

  10. #10
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    Bonjour,

    Tu as quelle erreur exactement ?
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. MS Project fait planter Access
    Par yoyo30 dans le forum Access
    Réponses: 4
    Dernier message: 22/09/2005, 09h56
  2. Réponses: 2
    Dernier message: 18/03/2005, 13h00
  3. probleme de requette qui fait planter powergres
    Par fehmitn dans le forum PostgreSQL
    Réponses: 1
    Dernier message: 15/09/2004, 18h48
  4. Réponses: 12
    Dernier message: 16/03/2004, 14h21
  5. fonction qui en fait planter une autre
    Par ickis dans le forum C
    Réponses: 5
    Dernier message: 18/08/2003, 21h33

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo