I have developed a java application that interacts with a database.
Now i've the folowing problem:
- I have a list retrieved from the database(about 200 records);
- for each, i do a Jlabel constructed from an html String;
- for each JLabel i construct a JPanel e add it to the main panel.
this works fine, but when there's an inactivity in the application
(about 30 minutes), the main panel disapear and the application
freeze. i don't know the reason for that (perhaps a lack of memomy
???).The application runs in a PIII 600mhz with 256 mb of ram.
Somebody can help me???
Thanks.
Have you tried removing the html, just use plain text in your JLabels?
Presumably you're using HTML because you want some nice formatting in your
JLabels..?
Have you tried adding your Resultset values into a JTable?
--
** http://www.tabletoolkit.com **
Aggregate a JTable to an arbitrary level to create your own pivot tables
"Jos? Cardoso" <josca...@yahoo.com> wrote in message
news:7eabb0c0.04083...@posting.google.com...
No, i need to show a lot of information for each row, thats why i choose html.
My program is something like that.
public class1{
public class1(){
...
}
public list1(){
// creates a JButton for each row
// each button listner creates a 2nd object -> class2 c2 = new class2()
c2.list2();
}
}
public class2{
public class2(){
...
}
public list2(){
// creates a JLabel for each row
}
}
I was seeing my taskmanager, and my memory goes to the 40.000 kb for javaw.exe,
when i run the program and enter in list2.
Then every time that i call list2, memory for javaw starts goes up to 80.000kb.
It seems like he isn't releasing the memory for objects created.
Hi,
Perhaps you are doing the list retrieval and JLabel creation right
in the Swing thread. That would explain the "freeze". You may want to
do the list retrieval in a separate thread. The creation of JLabels is
probably best done in a separate thread as well, though Sun apparently
recommends that UI components are best created in the Swing thread
under some situations. Then get the Swing thread to repaint the window
(using invokeLater(), for example).
The blog:
http://www.clientjava.com/blog/2004/08/20/1093059428000.html
presents an excellent approach to class threading problems with Swing.
Javalpha.
> No, i need to show a lot of information for each row, thats why i choose html.
have you considered/tried convertint that table to
a JList? A JList can accept a custom ListCellRenderer,
and AFAIU, only the items in the visible area are liable
to get the HTML overhead..
HTH
comp.lang.java,
comp.lang.java.developer,
comp.lang.java.help
Please also note that .developer is not a
valid group* and three groups too many **.
* <http://www.physci.org/codes/javafaq.jsp#groups>
** <http://www.physci.org/codes/javafaq.jsp#xpost>
Follow-Ups set top c.l.j.help only
--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Hi,
My problem isn't the retrieval, is after that. Java don't release the
memory used during the retrieval, and when the user click on the
button that make the same retrieval, the memory increases and after
that freezes.
Is there any way to release the memory or destroy the objects ?
> I think my problem is in java allocated memory.
Have you tried a JList?
<http://google.com/groups?selm=1rkhi290ye6qx%24.1bzin0hkbcvhy.dlg%4040tude.net>
There is no need for there to be any more than
a 'screenful' of the HTML (for rendering) at any time..
But, ..by the way, we have not seen an example
of your code, that might be the problem..
Cut out the D/B stuff and create an example
that creates 200 items for rendering using
dummy strings/HTML.
For further tips on an example..
<http://www.physci.org/codes/sscce.jsp>
Now, it seems you may not have got my earlier
reply, you are cross-posting to three groups,
one of which is not valid, *PLEASE* *STOP* *IT*.
Hi, here are some thoughts on how I would approach your problem.
First, try using the "-verbose:gc" option of your JVM, to see whether
the GC runs and, if so, whether it is successful in reclaiming memory.
You can also experiment with the "-Xmx" option to the JVM to increase
the maximum heap size (to say 128 MB) and see whether the allocated
memory saturates at some point. (BTW, the command "java -?" will
display all standard options available while "java -X" will display
non-standard options.)
Secondly, consider nulling out object references when you are sure
they won't be accessed again. CAUTION: Premature nulling is a bug and
may require lots of unit testing to catch via NullPointerExceptions.
Thirdly, consider running the GC under program control using
System.gc(). This is not recommended in general because it is best to
let the JVM decide when to run the GC. You could perhaps run the GC
before each list retrieval. (This is just a thought, I don't know
enough about your app to say whether this is a good idea.)
Finally, consider using garbage collectors other than the defaut. JDK
1.4 includes no less than <a href=
"http://www-106.ibm.com/developerworks/java/library/j-jtp11253/">
6 separate garbage collectors</a>. Without knowing more about your
application, I cannot say whether this will be helpful or which one is
a good candidate to try.
It sounds like you are using Windows Task manager to determine how much
memory you are using. If that is the case, you cannot simply look at
the default memory column that task manager presents. That only
displays the amount of physical memory used by the process (that is why
you see a great reduction when you minimize an application; Windows
swaps out its memory). Use the options of task manager to display the
virtual memory as well.
As an alternative, you can use System.freeMemory(), etc. to get the
information direct from the JVM.
HTH,
Ray
--
XML is the programmer's duct tape.