Out of memory error when using ImageView to render PNGs

All your problems with Audio, Video and Images.

Out of memory error when using ImageView to render PNGs

Postby underminedsk » Wed Mar 10, 2010 4:28 pm

Hey everyone,

I am getting a sporadic out of memory error when I render a PNG to the screen using ImageView. What is frustrating is that it doesn't happen every time...just most of the time.

Here is my code for my imageview class; it's very simple:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package com.ui;
  3.  
  4.  
  5.  
  6. import com.code.R;
  7.  
  8. import com.code.R.drawable;
  9.  
  10.  
  11.  
  12. import android.content.Context;
  13.  
  14. import android.graphics.Canvas;
  15.  
  16. import android.widget.ImageView;
  17.  
  18.  
  19.  
  20. public class Corners extends ImageView {
  21.  
  22.        
  23.  
  24.         public Corners(Context ctx) {
  25.  
  26.                 super(ctx);    
  27.  
  28.                 setCornersGreen();
  29.  
  30.                 setInvisible();
  31.  
  32.         }
  33.  
  34.        
  35.  
  36.         protected void onDraw(Canvas canvas) {
  37.  
  38.                 super.onDraw(canvas);
  39.  
  40.                 invalidate();
  41.  
  42.         }
  43.  
  44.        
  45.  
  46.         public void setVisible() {
  47.  
  48.                 setAlpha(200);
  49.  
  50.         }
  51.  
  52.        
  53.  
  54.         public void setInvisible() {
  55.  
  56.                 setAlpha(60);
  57.  
  58.         }
  59.  
  60.        
  61.  
  62.         public void setCornersRed() {
  63.  
  64.                 setImageResource(R.drawable.corners_red);
  65.  
  66.         }
  67.  
  68.        
  69.  
  70.         public void setCornersGreen() {
  71.  
  72.                 setImageResource(R.drawable.corners_green);
  73.  
  74.         }
  75.  
  76.        
  77.  
  78. }
  79.  
  80.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Obviously there is a memory leak somewhere...am I not doing something with garbage collection that I should be? I would think there would be an easy fix to this...

Zach
underminedsk
Developer
Developer
 
Posts: 26
Joined: Tue Mar 02, 2010 3:36 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 20 guests