Hi,<div>  I wrote this sample code and the resident memory of the process is increasing gradually over time. What could be the reason ? I don&#39;t see any obvious leaks in my program. Could it be that the API is not freeing/deleting memory ?<br>
<br></div><div>Regards,</div><div>Navin</div><div><br></div><div><br></div><div><br></div><div><div>package ovcollector;</div><div><br></div><div><br></div><div><br></div><div>import java.util.*;</div><div>import java.io.*;</div>
<div>import java.lang.management.ManagementFactory;</div><div><br></div><div>import org.apache.http.client.*;</div><div>import org.apache.http.params.*;</div><div>import org.ovirt.engine.sdk.Api;</div><div>import org.apache.http.pool.*;</div>
<div>import org.ovirt.engine.sdk.decorators.Host;</div><div>import org.ovirt.engine.sdk.decorators.HostStatistic;</div><div>import org.ovirt.engine.sdk.decorators.StorageDomain;</div><div>import org.ovirt.engine.sdk.decorators.VM;</div>
<div>import org.ovirt.engine.sdk.decorators.VMDisk;</div><div>import org.ovirt.engine.sdk.decorators.VMDiskStatistic;</div><div>import org.ovirt.engine.sdk.decorators.VMStatistic;</div><div>import org.ovirt.engine.sdk.decorators.VMs;</div>
<div>import org.ovirt.engine.sdk.entities.CPU;</div><div>import org.ovirt.engine.sdk.entities.Value;</div><div>import org.ovirt.engine.sdk.exceptions.ServerException;</div><div>import org.ovirt.engine.sdk.exceptions.UnsecuredConnectionAttemptError;</div>
<div>import org.ovirt.engine.*;</div><div><br></div><div>import javax.swing.JFrame;</div><div>import javax.swing.JPanel;</div><div>import javax.swing.JScrollPane;</div><div>import javax.swing.JTable;</div><div>import java.awt.Dimension;</div>
<div>import java.awt.GridLayout;</div><div>import java.awt.event.MouseAdapter;</div><div>import java.awt.event.MouseEvent;</div><div><br></div><div><br></div><div>public class collectHosts extends JPanel {</div><div><br></div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>/**</div><div><span class="Apple-tab-span" style="white-space:pre">                </span> * @param args</div><div><span class="Apple-tab-span" style="white-space:pre">                </span> */</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>public static String[] columnNames = {&quot;Host Name&quot;,</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>            &quot;Host uuid&quot;,</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>            &quot;Cpu Cores&quot;, &quot;Cpu Sockets&quot;,</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>            &quot;Memory.total&quot;,</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>            &quot;Memory.used&quot;,</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>            &quot;Memory.free&quot;,</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>            &quot;Memory.shared&quot;,&quot;Memory.buffers&quot;,&quot;Memory.cached&quot;,&quot;swap.total&quot;,&quot;swap.free&quot;,&quot;swap.used&quot;,&quot;swap.cached&quot;,&quot;ksm.cpu.current&quot;,</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>            &quot;cpu.current.user&quot;,&quot;cpu.current.system&quot;,&quot;cpu.current.idle&quot;,&quot;cpu.load.avg.5m&quot;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>            };</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>public static Object[][] data = </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>{&quot;blankvmname&quot;, &quot;blankuuid&quot;, new Double(0),new Double(0),new Double(0),new Double(0),new Double(0),new Double(0),new Double(0), new Double(0),</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>new Double(0),new Double(0),new Double(0),new Double(0),new Double(0),new Double(0),new Double(0),new Double(0),new Double(0)},</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>{&quot;blankvmname&quot;, &quot;blankuuid&quot;, new Double(0),new Double(0),new Double(0),new Double(0),new Double(0),new Double(0),new Double(0), new Double(0),</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>new Double(0),new Double(0),new Double(0),new Double(0),new Double(0),new Double(0),new Double(0),new Double(0),new Double(0)}<span class="Apple-tab-span" style="white-space:pre">                        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">                                                </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>};</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>public collectHosts() {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>        super(new GridLayout(1,0));</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>        </div><div><span class="Apple-tab-span" style="white-space:pre">        </span> </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>        final JTable table = new JTable(data, columnNames);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>        table.setPreferredScrollableViewportSize(new Dimension(500, 70));</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>        table.setFillsViewportHeight(true);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> </div><div><span class="Apple-tab-span" style="white-space:pre">        </span> </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>        //Create the scroll pane and add the table to it.</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>        JScrollPane scrollPane = new JScrollPane(table);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>        //Add the scroll pane to this panel.</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>        add(scrollPane);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>    }</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> </div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                        </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>  /**</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>     * Create the GUI and show it.  For thread safety,</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>     * this method should be invoked from the</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>     * event-dispatching thread.</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>     */</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>    private static void createAndShowGUI() {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>        //Create and set up the window.</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>        JFrame frame = new JFrame(&quot;Hosts&quot;);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>        //Create and set up the content pane.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>        collectHosts newContentPane = new collectHosts();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>        newContentPane.setOpaque(true); //content panes must be opaque</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>        frame.setContentPane(newContentPane);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>        //Display the window.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>        frame.pack();</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>        frame.setVisible(true);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>    }</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>private static final String URL = &quot;<a href="http://somehost:80/api">http://somehost:80/api</a>&quot;;</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>public static void main(String[] args) throws ClientProtocolException,ServerException, UnsecuredConnectionAttemptError,IOException {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>// TODO Auto-generated method stub</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>System.out.println(&quot;Hosts&quot;);</div><div>
<br></div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>while (true)</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>Api  api = new Api(URL,&quot;SOMEUSERNAME&quot;,&quot;SOMEPASSWORD&quot;);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>System.out.println(ManagementFactory.getRuntimeMXBean().getName()) ;</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span></div><div>
<span class="Apple-tab-span" style="white-space:pre">                                </span>List&lt;Host&gt;  hlist = api.getHosts().list();</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>Integer i=0,j=0;</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>for(Host obj: hlist)</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>j=0;</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>System.out.println(obj.getName()+ &quot;:&quot; + obj.getId() +&quot;:&quot;+ obj.getMemory()+&quot;:&quot; + obj.getCpu().getTopology().getCores() +&quot;:&quot;+</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                                                        </span>obj.getCpu().getTopology().getSockets());</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>data[i][j++]=obj.getName();</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                        </span>data[i][j++]=obj.getId();</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>data[i][j++]=obj.getCpu().getTopology().getCores();</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                        </span>data[i][j++]=obj.getCpu().getTopology().getSockets();</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>List&lt;HostStatistic&gt; lhs=obj.getStatistics().list();</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                        </span>for(HostStatistic obj1: lhs)</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                                                </span>System.out.println(obj1.getName());</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                                </span>List&lt;Value&gt; vll=obj1.getValues().getValues();</div><div><span class="Apple-tab-span" style="white-space:pre">                                                </span>for(Value vl:vll)</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                                </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                                                        </span>System.out.println(vl.getDatum());</div><div><span class="Apple-tab-span" style="white-space:pre">                                                        </span>data[i][j++]=vl.getDatum();</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>i++;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>try {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                        </span>Thread.sleep(10000);</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>} catch (InterruptedException e) {</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>// TODO Auto-generated catch block</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                        </span>e.printStackTrace();</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span></div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>/*</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>javax.swing.SwingUtilities.invokeLater(new Runnable() {</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>public void run() {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>            createAndShowGUI();</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>        }</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>});</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span></div><div><span class="Apple-tab-span" style="white-space:pre">                        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>List&lt;StorageDomain&gt; list_SD=api.getStorageDomains().list();</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>Integer i=0;</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>for(StorageDomain obj: list_SD)</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>System.out.println(obj.getName()+ &quot; | &quot; + obj.getUsed() + &quot; | &quot; + obj.getAvailable() + &quot; | &quot; + obj.getType());<span class="Apple-tab-span" style="white-space:pre">                </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>*/</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>} <span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div>
</div>