title: Dynamic Views created from Service not getting Garbage Collected
body: <p>I am working with Dynamic Views. I am running a service. When that service receive a Broadcast, I add Myview to window manager and remove that after user perform some action. But since service keeps running, I am adding this dynamic view 'myView', every-time I get broadcast. The problem is that they are not getting garbage collected after removing them from window manager and Heap Memory allocation getting increased continuously. Not sure why? Since it has bitmap inside it. After 5-6 actions I am getting OutOfMemoryException.   </p>
  
  <pre><code>   public class Myservice extends Service{                                                        
         private ParentView myView;
         WakeReceiver receiver;
  
          @Override
          public void onCreate()
          {
            super.onCreate();
            registerBroadCastReceiver();
          }
  
  
          //Performed when broadcast recieved
          public void addLayout() {
             WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
             myView = new ParentView(this);
             windowManager.addView(myView, getLayoutParam());
  
          }
  
          //Performed when user performs action on ParentView
          public void removeLayout() {
             WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
             windowManager.removeView(myView);
  
          }
  
           private void registerBroadCastReceiver() {
               IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
  
               receiver = new WakeReceiver();
               registerReceiver(receiver, filter);
  
          }
  
           private WindowManager.LayoutParams getLayoutParam() {
                   WindowManager.LayoutParams localLayoutParams = new     WindowManager.LayoutParams();
  
                   localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
                   localLayoutParams.height = (int) (WindowManager.LayoutParams.MATCH_PARENT);
                   return localLayoutParams;
  
          }
  
  
  }
  </code></pre>
  
  <p>//Code for Parent View</p>
  
  <pre><code> public class ParentView extends RelativeLayout {
  
  
        MyService topService;  
  
        public ParentView(MyService topService) {
           super(topService);
           this.topService = topService;
           LayoutInflater.from(topService).inflate(R.layout.parent_layout, this);                 
  
             setBackgroundDrawable(topService.getResources()
                .getDrawable(R.drawable.sample_image));
         }
  
         @Override
         public boolean onTouchEvent(MotionEvent event) {
           topService.removeLayout();  
        }
  
  
  
  }
  </code></pre>