Out of memory with Listbox

asked 2012-04-19 14:30:08 +0800

Neus gravatar image Neus
1415 14

My application is running out of memory when user (or users) loads several times a listbox.
I'm using ZK Bind 6 to populate listboxes. But I tried listmodel and a render, old beans and it always runs out of memory.
This is my code to fill all beans nowadays:

listaBeansOriginal.clear(); //List that contains all beans
listaBeansFiltrada.clear();//List linked with the listbox. It varies depends on user filters
for(int i = 1; i <= maxRegistros; i++){
	bean = NuevoBean(); //Instantiate a new bean
	LlenarBean(bean, i,listaDatos); //Fill the bean. listaDatos is an array with all necessary data to fill the bean
	listaBeansOriginal.add(bean);//Add the bean to the list
listaBeansFiltrada.addAll(listaBeansOriginal);//Loads all items to a list that will vary when user filters. We will work with this list. listaBeansOriginal never changes (it always contains all beans) and when user wants to clear filters listaBeansFiltrada is filled with listaBeansOriginal

listaBeansFiltrada is the one linked with the listbox
When user filters it loops through listaBeansFiltrada and remove all beans that don't coincide with the filter.
Also user can click on a refresh button and this code is called again to reload data. Every time user filters, refreshes or another user login and opens the window with the listbox the usage of java memory increase considerably.

Am I doing something wrong?? How can it be solved???

Thank you!

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2012-05-04 10:34:41 +0800

vincentjian gravatar image vincentjian
2245 6

updated 2012-05-04 10:38:17 +0800

Hi Neus,

I have tested a sample based on your description and did not see the problem with Java VisualVM.


package j3oqrqt$v3;

import java.util.ArrayList;
import java.util.List;

import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;

public class ListboxVM {

private List<Item> listaBeansOriginal;
private ListModelList<Item> listaBeansFiltrada;
private ListitemRenderer<Item> itemRenderer;
private String filter;

public ListModelList<Item> getModel() {
if(listaBeansFiltrada == null) {
listaBeansFiltrada = new ListModelList<Item>(getAllItems());
return listaBeansFiltrada;

public ListitemRenderer<Item> getRenderer() {
if (itemRenderer == null) {
itemRenderer = new ListitemRenderer<Item>() {
public void render(Listitem litem, Item item, int index) throws Exception {
new Listcell(item.getName()).setParent(litem);
return itemRenderer;

public String getFilter() {
return filter;

public void setFilter(String filter) {
this.filter = filter;

public void filter() {
for(int i = 1; i <= 10; i++) {
Item item = new Item(filter + " " + i);

private List<Item> getAllItems() {
listaBeansOriginal = new ArrayList<Item>();
listaBeansOriginal.add(new Item("David"));
listaBeansOriginal.add(new Item("Tom"));
listaBeansOriginal.add(new Item("Tim"));
listaBeansOriginal.add(new Item("Dove"));
listaBeansOriginal.add(new Item("John"));
listaBeansOriginal.add(new Item("Mary"));
listaBeansOriginal.add(new Item("Maria"));
return listaBeansOriginal;

public class Item {
private String name;
public Item(String name) {
this.name = name;
public String getName() { return name; }
public void setName(String name) { this.name = name; }

<div apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('j3oqrqt$v3.ListboxVM')">
<textbox value="@bind(vm.filter)" onChange="@command('filter')" instant="true"/>
<listbox model="@bind(vm.model)" itemRenderer="@bind(vm.renderer)">
<listheader label="name"></listheader>

Can you provide more detailed code?

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2012-04-19 14:30:08 +0800

Seen: 140 times

Last updated: May 04 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More