title: Would an assignment listed in the method cause a memory leak
body: <p>I would like to know if the possible resetting of amounts in the populateResponse() can cause a memory leak.    This class intent is to be used to process web service requests. My understanding is the BigDecimal created at (i) will be considered a local object instance if the call to padAmount() returns a new BigDecimal and will fall out of scope after the method execution and will be marked for GC. 
  Is this correct?</p>
  
  <pre><code>public SampleResponse processRequest(SampleRequest request){
          BigDecimal amount = new BigDecimal("12.3000"); // this will pad
          //BigDecimal amount = new BigDecimal("12.35"); // this will not pad, but return passed in amount
          return this.populateResponse(amount);
  
      }
  
      public SampleResponse populateResponse(BigDecimal amount){
          BigDecimal finalAmount = new BigDecimal(amount.toString(), new MathContext(21));
          SampleResponse response = new SampleResponse();
          response.setRespAmount(finalAmount.setScale(6, RoundingMode.UP).stripTrailingZeros()); //(i) Setting an amount
          Integer newScale = 2;
          BigDecimal paddedAmount = this.padAmt(newScale, finalAmount);
          response.setRespAmount(paddedAmount); //(ii) Possible reset of amount. Will this cause a memory leak if the paddedAmount has a new memory address
          return response;
  
      }
      public BigDecimal padAmt(int newScale, BigDecimal amount) {
  
          String amtWoTrailingZeros = amount.stripTrailingZeros().toPlainString();
          try {
              int decDigitsInAmt = this.getNumberOfDecimalPlaces(amtWoTrailingZeros);
              if(newScale &gt; decDigitsInAmt){
                  System.out.println("Pad amount with zeros");
                 return new BigDecimal(amtWoTrailingZeros).setScale(newScale);
              }else {
                  System.out.println("No Need to pad amount with zeros");
                  return amount;
              }
          } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
              System.out.println("Exception caught here: " +e);
              return amount;
          }
  
      }
  
      public int getNumberOfDecimalPlaces(String decimalNumber) throws Exception{
          if (decimalNumber == null){
              throw new Exception("decimal number is NULL");
          }
          int index = decimalNumber.indexOf(".");
          return index &lt; 0 ? 0 : decimalNumber.length() - index - 1;
      }
  
      public static void main (String args[]){
          RequestProcessor rp = new RequestProcessor();
          SampleRequest request = new SampleRequest();
          SampleResponse response = rp.processRequest(request);
          System.out.println("Sample response amount: " +response.getRespAmount().toPlainString());
      }
  </code></pre>