title: Memory size increasing every time I update application on same device
body: <p>The problem is whenever I update my application on my device the size of the internal memory increases to the size of the application.</p>
  
  <p>I have a single application which runs on tablet associated to the application. i.e. only that application will run on that tablet and it will be a boot application of the tablet. Due to this feature I have added code to update the application internally within the application. I have written code to download the application from my server and update the application with the new version. Also I have written some code to check the used memory and total memory of the internal memory on the device.</p>
  
  <p>Note: There is no external memory i.e. there is no sd-card available for this operation.</p>
  
  <p>The scenario is.</p>
  
  <p>Step 1) I download a new version of the application within the application and update it.</p>
  
  <p>Step 2) After updating when the application restarts I have written code on a splash screen to delete all the old application data. The old data consists of application cache, stored images, downloaded apk and clearing folders created by the application.</p>
  
  <p>Step 3) I reboot the device to check the working functionality. Now after the application starts I check the memory, suppose previously used/total memory was 0.45GB/5.08GB. Now I follow step 1 again.</p>
  
  <p>Step 4) After rebooting when I check for the internal memory size, surprisingly the memory size has increased by 120MB which is the size +-1MB of my application size. i.e. the old size of the internal memory used/total 0.45Gb/5.08Gb the increased size of internal memory after the reboot and updating the application is 0.57GB/5.08GB</p>
  
  <p>I have tried to check the data/data folder but its size also remains the same but the size of internal memory increased to the size of the application. I do not know what is increasing the size of the internal memory.</p>
  
  <p>Is there any place or thing that OS is keeping in the application size data or am I missing something in the application which is causing the increased size of the internal memory to the exact size ?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Code to delete videos which I am keeping in specific path</p>
  
  <pre><code>/**
       * Method to delete all the videos from SD card on startup
       * */
      public static void deleteAllVideos() {
          new Thread(new Runnable() {
              @Override
              public void run() {
                  File dir = new File(directoryPath);
                  try {
                      File[] files = dir.listFiles();
                      for (int i = 0; i &lt; files.length; i++) {
                          files[i].delete();
                      }
                  } catch (Exception e) {
                  }
                  dir.delete();
              }
          }).start();
      }
  </code></pre>
  
  <p>Code to delete APK from the device</p>
  
  <pre><code>    public static void deleteFile() {
          String imagePath = Environment.getExternalStorageDirectory()
                  .getAbsolutePath();
          File folder = new File(imagePath);
          try {
              File[] filenamestemp = folder.listFiles();
              for (int i = 0; i &lt; filenamestemp.length; i++) {
                  if (filenamestemp[i].getAbsolutePath().toString()
                                  .endsWith(".apk"))
                      filenamestemp[i].delete();
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>Deleting Application Cache and cached images from memory</p>
  
  <pre><code>/**
       * Method to clear application data
       * 
       * @param Context
       *            context of screen
       * */
      public static void clearApplicationData(Context context) {
          File cache = context.getCacheDir();
          File appDir = new File(cache.getParent());
          if (appDir.exists()) {
              String[] children = appDir.list();
              for (String s : children) {
                  if (!s.equals("lib")) {
                      deleteDir(new File(appDir, s));
                  }
              }
          }
  
          try {
              File cacheDir = null;
              if (android.os.Environment.getExternalStorageState().equals(
                      android.os.Environment.MEDIA_MOUNTED)) {
                  cacheDir = new File(
                          android.os.Environment.getExternalStorageDirectory(),
                          Global.CACHE_DIRECTORY);
              } else {
                  cacheDir = context.getCacheDir();
              }
              if (cacheDir.exists()) {
                  File[] filesList = cacheDir.listFiles();
                  for (File file : filesList) {
                      file.delete();
                  }
              }
  
          } catch (Exception e) {
          }
  
      }
  </code></pre>
  
  <p>These are the deleting codes which I am using to delete all the contents that I am creating in internal Memory including application cache</p>