2012-09-22 21 views
8

मेरे पास इस फ़ाइल में मेमोरी रिसाव है, मुझे बिल्कुल सही नहीं मिल रहा है, लेकिन मुझे लगता है कि यह छवि है ->(Bitmap bm = BitmapFactory.decodeFile(filename)), मैंने कई अलग-अलग प्रयास किए हैं तरीकों से लेकिन मैं इसे काम नहीं कर सकता।PHP सर्वर पर छवि के साथ एक फॉर्म भेजने की कोशिश करते समय एंड्रॉइड में मेमोरी लीक

package prod.vegs; 

//All imports here but not need to write them all now :-) 


public class ProductForm extends Activity { 

private static int TAKE_PICTURE = 1; 
private static int SELECT_PICTURE = 2; 

//JSON Response node names 
private static String KEY_SUCCESS = "success"; 
private static String ERROR_MSG = "error_msg"; 
private static String KEY_TYPES = "subtypes"; 
private static String TYPE_NAME = "name"; 
private static String TYPE_ID = "id_type"; 
private static String PRODUCT_ID = "id_product"; 

private JSONObject json; 
private JSONParser jsonParser; 
private String barcodeStr; 
private String filename; 
private int code; 
private ProgressDialog dialog; 
private TypeClass[] items; 
private TypeClass[] sub_items; 

//Declare assets objects 
Spinner type; 
Spinner subtype; 
TextView errorMsg; 
TextView description; 
TextView name; 
Button camera; 
Button gallery; 
Intent intent; 
ImageView preview; 
Bundle bundle; 
LinearLayout errorMsgContainer; 

Context context; 

public void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
    setContentView(R.layout.product_form); 
    context = this; 

    Bundle b = getIntent().getExtras(); 
    barcodeStr = b.getString("barcode"); 

    jsonParser = new JSONParser(); 
    dialog = new ProgressDialog(this); 
    dialog.setMessage(getString(R.string.loading)); 
    dialog.setTitle(getString(R.string.progress)); 
    dialog.setCancelable(true); 

    //Set assets 
    name = (TextView) findViewById(R.id.productName); 
    description = (TextView) findViewById(R.id.productDescription); 
    errorMsg = (TextView) findViewById(R.id.error_msg); 
    errorMsgContainer = (LinearLayout) findViewById(R.id.error_msg_container); 
    type = (Spinner) findViewById(R.id.productParentType); 
    subtype = (Spinner) findViewById(R.id.productType); 
    camera = (Button) findViewById(R.id.productCamera); 
    gallery = (Button) findViewById(R.id.productGallery); 
    preview = (ImageView) findViewById(R.id.productPreview); 
    filename = Environment.getExternalStorageDirectory() + String.format(getString(R.string.api_product_form_picture_file), barcodeStr); 

    Boolean fromScanner = b.getBoolean("scanner"); 
    if (fromScanner == true) { 

     AlertDialog.Builder alertbox = new AlertDialog.Builder(this); 
     alertbox.setMessage(getString(R.string.insert_product)); 
     alertbox.setPositiveButton(getString(R.string.yes), 
      new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface arg_1, int arg_num) { 
        final Functions function = new Functions(); 
        List<NameValuePair> params = new ArrayList<NameValuePair>(); 
        String url = String.format(getString(R.string.api_product_form_types_url), getString(R.string.api_url)); 
        json = function.loadJSONUrl(url, params); 
        if(json != null){ 
         try { 
          if (json.getString(KEY_SUCCESS) != null) { 
           String res = json.getString(KEY_SUCCESS); 
           if(Integer.parseInt(res) == 1){ 

            JSONArray types = json.getJSONArray(KEY_TYPES); 
            items = convertJSONArray(types); 

            SpinAdapter listViewArrayAdapter = new SpinAdapter(context, android.R.layout.simple_spinner_item, items); 
            listViewArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
            type.setAdapter(listViewArrayAdapter); 
            type.setOnItemSelectedListener(new OnItemSelectedListener(){ 
             public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) { 
              try { 
               String url = String.format(getString(R.string.api_subtypes_id_url), getString(R.string.api_url), ((TypeClass) type.getSelectedItem()).getId()); 
               List<NameValuePair> params = new ArrayList<NameValuePair>(); 
               JSONObject json_subtypes = function.loadJSONUrl(url, params); 
               if (json_subtypes.getString(KEY_SUCCESS) != null) { 
                JSONArray subtypes = json_subtypes.getJSONArray(KEY_TYPES); 
                sub_items = convertJSONArray(subtypes); 
                SpinAdapter subTypeAdapter = new SpinAdapter(context, android.R.layout.simple_spinner_item, sub_items); 
                subTypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
                subtype.setAdapter(subTypeAdapter); 
                subtype.setPrompt("Selecciona la cateogría"); 
               } 
              } catch (Exception e) { 
               e.printStackTrace(); 
              } 
             } 

             public void onNothingSelected(AdapterView<?> args) { 
              //Auto-generated method stub 
             } 
            }); 
            type.setPrompt("Selecciona la cateogría"); 

            //camera action 
            camera.setOnClickListener(new View.OnClickListener() { 
             public void onClick(View view) { 
              intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
              int timeMili = (int) (System.currentTimeMillis()); 
              filename = Environment.getExternalStorageDirectory() + "/" + timeMili + ".jpg"; 
              Uri output = Uri.fromFile(new File(filename)); 
              intent.putExtra(MediaStore.EXTRA_OUTPUT, output); 
              code = TAKE_PICTURE; 
              startActivityForResult(intent, code); 
             } 
            }); 

            //gallery action 
            gallery.setOnClickListener(new View.OnClickListener() { 
             public void onClick(View view) { 
              intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI); 
              code = SELECT_PICTURE; 
              startActivityForResult(intent, code); 
             } 
            }); 

            //button of the form 
            Button button = (Button) findViewById(R.id.button); 
            button.setOnClickListener(new View.OnClickListener() { 
             public void onClick(View view) { 
              if (!NetworkHelper.CheckNetworkStatus(view.getContext())) { 
               return; 
              } 
              bundle = new Bundle(); 
              bundle.putString("barcode", barcodeStr.toString()); 
              bundle.putString("name", name.getText().toString()); 
              bundle.putString("description", description.getText().toString()); 
              bundle.putString("type_id", ((TypeClass) subtype.getSelectedItem()).getId()); 

              if (_checkFormValues()) { 
               new SendDataJSON().execute(view); 
              } else { 
               Toast.makeText(view.getContext(), getString(R.string.error_form_incomplete), Toast.LENGTH_LONG).show(); 
              } 
             } 
            }); 

           } else { 
            errorMsg.setText(json.getString(ERROR_MSG)); 
            errorMsgContainer.setVisibility(LinearLayout.VISIBLE); 
           } 
          } 
         } catch (JSONException e) { 
          e.printStackTrace(); 
         } 
        } else { 

        } 
       } 
     }).setNegativeButton("No", 
      new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface arg0, int arg1) { 
        Intent myIntent = new Intent(ProductForm.this, CaptureActivity.class); 
        startActivity(myIntent); 
        finish(); 
       } 
     }).show(); 

    } else { 
     finish(); 
    } 

} 

class SendDataJSON extends AsyncTask<View, Void, View>{ 

    @Override 
    protected View doInBackground(View... views) { 

     String url = String.format(getString(R.string.api_product_form_url),getString(R.string.api_url)); 
     HttpPost httpPost = new HttpPost(url); 

     try { 
      // Add your data 
      MultipartEntity entity = new MultipartEntity(); 

      File photo = new File(filename); 
      if (photo.exists()) { 
       //create the compressed image to send     
       //create the file to send the image 
       File sd = Environment.getExternalStorageDirectory(); 
       File data = Environment.getDataDirectory(); 
       if (!sd.canWrite()) { sd = data; } 
       String destinationFolderPath = sd + "/" + getString(R.string.app_dir) + "/"; 
       String destinationImageName= "photo_" + bundle.getString("barcode") + ".jpg"; 

       //create the folder to store it 
       File destinationFolder = new File(destinationFolderPath); 
       if (!destinationFolder.exists()) { 
        destinationFolder.mkdirs(); 
       } 

       File destination = new File(destinationFolder, destinationImageName); 
       FileOutputStream out = new FileOutputStream(destination); 

       Bitmap bm = BitmapFactory.decodeFile(filename);     
       int width = bm.getWidth(); 
       int height = bm.getHeight(); 
       int max_value = 1024; 
       int max = Math.max(width,height); 
       if (max > max_value) { 
        width = width * max_value/max; 
        height = height * max_value/max; 
       } 

       //Make the new image with the new size values 
       try { 
        Bitmap bm2 = Bitmap.createScaledBitmap(bm, width, height, true); 
        //Compress the image 
        bm2.compress(CompressFormat.JPEG, 75, out);      
        out.flush(); 
        out.close();       
        destination = new File(destinationFolder, destinationImageName);       
        FileBody filePhoto = new FileBody(destination); 
        entity.addPart("image", filePhoto); 
       } catch (Exception e) { 
        Log.w(ProductForm.class.getSimpleName(), e); 
       } 

      } 
      SharedPreferences userSettings = getSharedPreferences("UserPreferences", Context.MODE_PRIVATE); 
      Charset chars = Charset.forName("UTF-8"); 
      entity.addPart("barcode", new StringBody(bundle.getString("barcode"),chars)); 
      entity.addPart("name", new StringBody(bundle.getString("name"),chars)); 
      entity.addPart("description", new StringBody(bundle.getString("description"),chars)); 
      entity.addPart("id_type", new StringBody(bundle.getString("type_id"))); 
      entity.addPart("uid",new StringBody(userSettings.getString("uid", ""),chars)); 
      httpPost.setEntity(entity); 
      HttpClient httpclient = new DefaultHttpClient(); 
      httpclient.execute(httpPost); 

     } catch (IOException e) { 
      // 
     } 

     return views[0]; 
    } 

    @Override 
    protected void onPreExecute() { 
     dialog.setMax(100); 
     dialog.setProgress(0); 
     dialog.show(); 
    } 

    @Override 
    protected void onPostExecute(View view) { 
     //redirect to the product page   
     setContentView(R.layout.product_barcode);   
     String url = String.format(getString(R.string.api_product_barcode_url), getString(R.string.api_url), bundle.getString("barcode")); 
     new LoadJSONBarcode().execute(url); 
    } 
} 

//Send data to server and receive respond 
private class LoadJSONBarcode extends AsyncTask<String, Void, JSONObject>{ 

    @Override 
    protected JSONObject doInBackground(String... urls) { 
     List<NameValuePair> params = new ArrayList<NameValuePair>(); 
     json = new JSONObject(); 
     json = jsonParser.getJSONFromUrl(urls[0], params); 
     return json; 
    } 

    @Override 
    protected void onPreExecute() { 
     dialog.setMax(100); 
     dialog.setProgress(0); 
     dialog.show(); 
    } 

    @Override 
    protected void onPostExecute(JSONObject json) { 

     if (json != null) { 
      try { 

       if (json.getString(KEY_SUCCESS) != null) { 
        String res = json.getString(KEY_SUCCESS); 
        if(Integer.parseInt(res) == 1){ 
         View view = findViewById(R.id.productBarcodeXML);      
         Intent myIntent = new Intent(view.getContext(), Product.class); 
         Bundle b = new Bundle(); 
         b.putString("id", json.getString(PRODUCT_ID)); 
         myIntent.putExtras(b); 
         view.getContext().startActivity(myIntent); 
        } else { 
         errorMsg.setText(json.getString(ERROR_MSG)); 
         errorMsgContainer.setVisibility(LinearLayout.VISIBLE); 
        } 
        dialog.dismiss(); 
       } 

      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 

} 

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == TAKE_PICTURE) { 
     if (data != null) { 
      if (data.hasExtra("data")) { 
       preview.setImageBitmap((Bitmap) data.getParcelableExtra("data")); 
       preview.setVisibility(ImageView.VISIBLE); 
      } 
     } else { 
      preview.setImageBitmap(BitmapFactory.decodeFile(filename)); 
      preview.setVisibility(ImageView.VISIBLE); 
      new MediaScannerConnectionClient() { 
       private MediaScannerConnection msc = null; { 
        msc = new MediaScannerConnection(getApplicationContext(), this); msc.connect(); 
       } 
       public void onMediaScannerConnected() { 
        msc.scanFile(filename, null); 
       } 
       public void onScanCompleted(String path, Uri uri) { 
        msc.disconnect(); 
       } 
      };    
     } 
    } else if (requestCode == SELECT_PICTURE){ 
     if (data != null){ 
      Uri selectedImage = data.getData(); 
      InputStream is; 
      String[] filePathColumn = {MediaStore.Images.Media.DATA}; 
      Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); 
      cursor.moveToFirst(); 

      int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
      filename = cursor.getString(columnIndex); 
      cursor.close(); 

      try { 
       is = getContentResolver().openInputStream(selectedImage); 
       BufferedInputStream bis = new BufferedInputStream(is); 
       Bitmap bitmap = BitmapFactory.decodeStream(bis);    
       preview.setImageBitmap(bitmap);  
       preview.setVisibility(ImageView.VISIBLE); 
      } catch (FileNotFoundException e) { 

      } 
     } 
    } 
} 

private TypeClass[] convertJSONArray(JSONArray jsonArray){ 
    int len = jsonArray.length(); 
    TypeClass[] t = new TypeClass[len]; 
    if (jsonArray != null) { 
     for (int i=0;i<len;i++){ 
      try { 
       JSONObject o = jsonArray.getJSONObject(i); 
       t[i] = new TypeClass(); 
       t[i].setName(o.getString(TYPE_NAME)); 
       t[i].setId(o.getString(TYPE_ID)); 
      } catch (JSONException e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
    return t; 
} 

protected boolean _checkFormValues() { 

    boolean result = true; 

    if (name.getText().length() == 0) { 
     name.requestFocus(); 
     result = false; 
    } 
    if (((TypeClass) subtype.getSelectedItem()).getId() == null){ 
     subtype.requestFocus(); 
     result = false; 
    } 
    return result; 
} 

} 

त्रुटि लॉग

11-07 23:55:26.914: E/AndroidRuntime(15457): FATAL EXCEPTION: AsyncTask #3 
11-07 23:55:26.914: E/AndroidRuntime(15457): java.lang.RuntimeException: An error occured while executing doInBackground() 
11-07 23:55:26.914: E/AndroidRuntime(15457): at android.os.AsyncTask$3.done(AsyncTask.java:278) 
11-07 23:55:26.914: E/AndroidRuntime(15457): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273) 
11-07 23:55:26.914: E/AndroidRuntime(15457): at java.util.concurrent.FutureTask.setException(FutureTask.java:124) 
11-07 23:55:26.914: E/AndroidRuntime(15457): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307) 
11-07 23:55:26.914: E/AndroidRuntime(15457): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 
11-07 23:55:26.914: E/AndroidRuntime(15457): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 
11-07 23:55:26.914: E/AndroidRuntime(15457): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 
11-07 23:55:26.914: E/AndroidRuntime(15457): at java.lang.Thread.run(Thread.java:864) 
11-07 23:55:26.914: E/AndroidRuntime(15457): Caused by: java.lang.OutOfMemoryError: (Heap Size=35491KB, Allocated=27993KB) 
11-07 23:55:26.914: E/AndroidRuntime(15457): at android.graphics.BitmapFactory.nativeDecodeFile(Native Method) 
11-07 23:55:26.914: E/AndroidRuntime(15457): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:373) 
11-07 23:55:26.914: E/AndroidRuntime(15457): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:443) 
11-07 23:55:26.914: E/AndroidRuntime(15457): at prod.vegs.ProductForm$SendDataJSON.doInBackground(ProductForm.java:272) 
11-07 23:55:26.914: E/AndroidRuntime(15457): at prod.vegs.ProductForm$SendDataJSON.doInBackground(ProductForm.java:1) 
11-07 23:55:26.914: E/AndroidRuntime(15457): at android.os.AsyncTask$2.call(AsyncTask.java:264) 
11-07 23:55:26.914: E/AndroidRuntime(15457): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 
11-07 23:55:26.914: E/AndroidRuntime(15457): ... 4 more 
+3

अच्छा, छवियां कितनी बड़ी हो सकती हैं? यदि आप 5 मेगापिक्सेल फोटो लोड करते हैं, और उसके बाद पुराने को एक मेमोरी में रखते हुए इसे 1k * 1k तक आकार दें, तो आप केवल एक ही छवि द्वारा 24 एमबी के साथ समाप्त हो सकते हैं। – Jave

+0

http://stackoverflow.com/a/12819091/726863 –

+0

आपकी पोस्ट पर बहुत सारे कोड हैं, क्या आप इसे सबसे प्रासंगिक में कम कर सकते हैं, या अप्रासंगिक कोड को हटाने पर विचार कर सकते हैं। – Siddharth

उत्तर

10

बिटमैप बहुत बड़ा स्मृति उपभोक्ता हैं। स्मृति में लोड होने के बाद बड़ा मुद्दा हो सकता है। जब आप एक नया बिटमैप डीकोड करते हैं तो आपको BitmapFactory.Options का उपयोग करने पर विचार करना चाहिए। इसके अलावा, आपको bm2 की आवश्यकता नहीं है। इसके बजाय, इस के साथ कि लाइन की जगह:

bm = Bitmap.createScaledBitmap(bm, width, height, true); 

अंत में, यदि आप कोई अन्य विकल्प हैं, आप अपने ऐप के ढेर आकार अपने AndroidManifest.xml में आवेदन विशेषता android:largeHeap="true" का उपयोग कर बढ़ा सकते हैं। इस विकल्प की आवश्यकता नहीं होनी चाहिए - और केवल अत्यंत ग्राफिक-गहन अनुप्रयोगों के लिए विचार किया जाना चाहिए।

संपादित

एक और लिंक आप के अनुकूलन बिटमैप उपयोग के लिए उपयोगी हो सकते हैं: http://developer.android.com/training/tv/optimizing-layouts-tv.html#HandleLargeBitmaps

+0

फिल की टिप्पणी पर विस्तार करने के लिए, जब आप पहली 'बिटमैप' लोड करते हैं तो आप 'inJustDecodeBounds' विकल्प सेट करना चाहेंगे: http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inJustDecodeBounds – twaddington

+0

मैंने कोशिश की है और यह काम नहीं करता है, लेकिन यह केवल कुछ मॉडलों में है कि यह काम नहीं करता है क्योंकि यह नेक्सस एचटीसी नायक इत्यादि में ठीक है। अब मैं इसे एचटीसी वन एस के साथ परीक्षण कर रहा हूं और यह सभी मेमोरी खाती है , लेकिन अब तक आपका जवाब अधिक उपयोगी है। धन्यवाद, मैं ठीक होने तक कोशिश करता रहूंगा और मैं सवाल अपडेट कर दूंगा। – jonaypelluz

2

कुछ सामान्य संकेत: जैसा कि @Phil सुझाव

  • , Bitmap वस्तुओं एक बहुत खाते हैं एंड्रॉइड में स्मृति की। बिटमैप्स को पकड़ने के लिए आपको हमेशा SoftReferences का उपयोग करना चाहिए ताकि जब आवश्यक हो तो ओएस स्मृति को मुक्त कर सके।
  • जब आप उनके साथ समाप्त हो जाते हैं तो आपको रूपांतरण बिटमैप्स (यानी, bm2 परिवर्तनीय) को फेंकने के लिए recycle() विधि का भी उपयोग करना चाहिए।
  • जैसा कि यह लगता है, के रूप में पायरनोइड के रूप में, NULL पर बिटमैप्स को सेट करते समय आप कचरा कलेक्टर को संकेत देने के लिए एक अच्छा अभ्यास है कि उन्हें एकत्र किया जा सकता है। हालांकि, एंड्रॉइड में मैन्युअल रूप से जीसी को कॉल करने वाले सामान्य नियम के रूप में या तो मामले खराब होते हैं या इसका कोई प्रभाव नहीं पड़ता है।
  • और अंत में, profile your applicationddms का उपयोग कर!
0

निश्चित रूप से कह नहीं कर सकते, जैसा कि मैंने जावा डेवलपर नहीं कर रहा हूँ, लेकिन नेट में BitMap calss IDisposable है और के रूप में यह उपयोग में नहीं है जैसे ही पुनर्नवीनीकरण किया जा करने के लिए सिफारिश की है।
क्या आपको बिटमैप लोडिंग के बाद अपनी याददाश्त मुक्त करनी चाहिए?

4

बिटमैप्स बहुत मेमोरी का उपयोग स्पष्ट है। आप प्रभावी रूप से

  • बिटमैप्स उपयोग करने के लिए याद रखें कि ड्रॉएबल में अपने png के स्वचालित रूप से एंड्रॉयड से स्क्रीन आकार के आधार बदला गया है निम्नलिखित की देखभाल की जरूरत है। और यह बहुत मेमोरी लेता है। एंड्रॉइड छवियों का आकार बदलता नहीं है अगर इसे सही ड्रॉबल फ़ोल्डर में अपने आवश्यक आकार/पैमाने की छवियां मिलती हैं। तो सभी ldpi फ़ाइलों को कॉपी करने के साथ शुरू करने के लिए hdpi भी। इससे आपकी स्मृति उपयोग कम से कम 40% कम हो जाएगी। मुझे पता है कि यह कैसा लगता है, लेकिन यह सच है, मैनिफेबल में डीबग्रेबल = सत्य का उपयोग करके अपने ऐप को प्रोफाइल करें, और डीडीएमएस का उपयोग करके ढेर उपयोग करें। परिवर्तन करें और बिल्कुल वही परिदृश्य चलाएं, आपको 40% की कमी दिखाई देगी।
  • जब आप अपना बिटमैप पढ़ते हैं, तो इसे घटाएं।केवल CreateBitmap का उपयोग न करें, क्योंकि यह पूरी फ़ाइल को पढ़ेगा और बहुत अधिक मेमोरी का उपयोग करेगा। इसके बजाय BitmapOptions का उपयोग करें और इसे घटाएं। इसे स्केल करने के लिए आपको पहले अपने विकल्पों को सेट करने की आवश्यकता है, और फिर अपने विकल्पों को CreateBitmap कॉल पर पैरामीटर के रूप में उपयोग करें। Here एक अच्छा लिंक है। स्टैक ओवरफ्लो पर अधिक खोजें आपको कुछ और दिलचस्प प्रतिक्रिया मिलेगी।
  • यदि आपके पास आपके ड्रॉबल्स में 1024X512 हैं, तो उन्हें स्केल करें। या नई फाइलें बनाएं जो स्पष्ट हैं लेकिन आकार में छोटी हैं। Mdpi के लिए इन फ़ाइलों का उपयोग करें, ldpi हटाएं। अपने एचडीपीआई फ़ोल्डर के लिए 1024X512 का प्रयोग करें।
  • छोटी फ़ाइलों का उपयोग करने की संभावना का अन्वेषण करें, आकार के अनुसार क्रमबद्ध करें और इसके साथ थोड़ा सा खेलें। Xml फ़ाइलों के लिए ग्रहण पर आलेखीय दृश्य वास्तव में साफ है, और अपेक्षाकृत बग मुक्त है। इसका इस्तेमाल करें।
  • संपादित: कचरा संग्रह के लिए अपने बिटमैप को खाली करना न भूलें। यह सबसे महत्वपूर्ण है।
+0

मैं डीडीएमएस का उपयोग कर रहा हूं और अब मुझे पता है कि मेमोरी लीक कहां है। जब मैंने फ़ोल्डर से छवि को चुना या मैं लेता हूं, तो उस क्षण में मैं फिलिप उत्तर और तुम्हारी यादों को याद करता हूं, धन्यवाद, मैं इसे ठीक करने की कोशिश कर रहा हूं, धन्यवाद! – jonaypelluz

+0

आपको एक और फिक्स जोड़ा गया है जिसे आपको बनाना है। – Siddharth

0

हाँ एक मेमोरी कैश मूल्यवान एप्लिकेशन मेमोरी लेने की लागत पर बिटमैप्स तक तेजी से पहुंच प्रदान करता है। यदि LruCache समस्या का समाधान नहीं कर सकता है तो आप इसे आजमा सकते हैं: ImageManager, क्लास ImageManager में, इसमें एक विधि रीसायकल बिटमैप्स है।

+0

एलआरयूकेचे का उपयोग केवल तभी सिफारिश की जाती है जब वह बिटमैप्स का पुन: उपयोग कर रहा हो। यहां मामला ऐसा नहीं है। बस बिटमैप का उपयोग करना एक दुर्घटना का कारण बन रहा है। – Siddharth

+0

@jonaypelluz शायद, आप इसे ImageManager श्रेणी में [ImageManager] (http://blog.pseudoblue.com/2010/08/15/android-bitmaps-and-memory-leaks/) आज़मा सकते हैं, इसमें एक विधि रीसायकल बिटमैप्स है । – Jamesprite

+0

मैंने LruCache देखा है और मैं इसे किसी अन्य ऐप में कार्यान्वित करने जा रहा था, लेकिन मुझे लगता है कि इसे जांचने के लिए मुझे इसके साथ जाना होगा ताकि यह समस्या हल हो सके। धन्यवाद! – jonaypelluz