title: Android studio memory leak activity does not finish in a thread
body: <p>It seems like my activity does not finish properly because I get a bigger memory consumption every time I launch and close it. Can someone suggest me an idea? Here is the code: </p>
  
  <pre><code>new Thread(new Runnable() {
          @Override
          public void run() {
              Looper.prepare();
              ProgressDialog mProgressDialog = new ProgressDialog(thisActivity);
              mProgressDialog.setTitle("Getting location");
              mProgressDialog.setMessage("Please wait while the device is being located.");
              mProgressDialog.show();
              long startTime = SystemClock.currentThreadTimeMillis();
              long time = SystemClock.currentThreadTimeMillis();
              while (mLastLocation == null)
              {
                  if(SystemClock.currentThreadTimeMillis() - startTime &gt;= 5000){
                      mLastLocation = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                  }
                  if(SystemClock.currentThreadTimeMillis() - time &gt;= 1000) {
                      if (ActivityCompat.checkSelfPermission(thisActivity, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &amp;&amp; ActivityCompat.checkSelfPermission(thisActivity, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                          return;
                      }
                      mLocationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, mLocationListener, null);
                      time = SystemClock.currentThreadTimeMillis();
                  }
              }
  
              String date = new SimpleDateFormat("dd/MM/yyyy").format(new Date());
  
              ServiceModel model = new ServiceModel(0, Globals.LoggedUser.Id, ScheduleAdapter.currentToilet.Id, edt_note.getText().toString(), photo, null, reason, date, mLastLocation.getLatitude(), mLastLocation.getLongitude());
              Globals.DomainServiceManager.ServiceRepository.Create(model);
              runOnUiThread(new Runnable() {
                  @Override
                  public void run() {
                      photo = null;
                      imv_camera.setImageBitmap(null);
                      ActivityScheduleList.setToolbarPosition(0, DATA_NOT_CAPTURED);
                  }
              });
              mProgressDialog.dismiss();
              ActivityNotServeced.this.finish();
          }
      }).start();
  </code></pre>