title: Getting out of memory error while reading responce from web service
body: <p>I am trying to call a web service, the response contains a big string, getting out of memory issue the code is</p>
  
  <pre><code> URL u = new URL(SharedVariables.server);
             URLConnection uc = u.openConnection();
             HttpURLConnection connection = (HttpURLConnection) uc;
             connection.setConnectTimeout(SharedVariables.connectionTimedOutValue);
             connection.setDoOutput(true);
             connection.setDoInput(true);
             connection.setRequestProperty("SOAPAction", SOAP_ACTION);
             connection.setRequestMethod("POST");
             connection.setRequestProperty("Content-type", "text/xml; charset=utf-8");
  
             String xmldata = "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;" + 
                              "&lt;soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"&gt; "+ 
                              "&lt;soap:Body&gt;"+
                              "&lt;GetCaseCriminalTicketLinks xmlns=\"http://tempuri.org/\"&gt;"+   
                              Req.getRequestXml()+                            
                              "&lt;/GetCaseCriminalTicketLinks&gt;"+
                              "&lt;/soap:Body&gt;"+
                              "&lt;/soap:Envelope&gt;";        
  
             OutputStream out = connection.getOutputStream();
                  Writer wout = new OutputStreamWriter(out);
                  wout.write(xmldata);
                  wout.flush();                   
                  out.flush();                    
  
  
                BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()),8 * 1024);
  
                String result;    
  
                while ((result=rd.readLine()) != null) {
  
  
                int length = result.length();               
                 String temp = result.substring(316, (length - 100));           
  
                 JSONObject tempJson = new JSONObject(temp);}
  </code></pre>
  
  <p>The log is</p>
  
  <pre><code>Caused by: java.lang.OutOfMemoryError
  at java.lang.String.&lt;init&gt;(String.java:513)
  at java.lang.AbstractStringBuilder.toString(AbstractStringBuilder.java:650)
  at java.lang.StringBuilder.toString(StringBuilder.java:664)
  at java.io.BufferedReader.readLine(BufferedReader.java:398)
  </code></pre>
  
  <p>this line is causing   </p>
  
  <pre><code>while ((result=rd.readLine()) != null) 
  </code></pre>
  
  <p>Any suggestions ?</p>
  
  <p>Thanks</p>