Forums Register Login

About String usage

+Pie Number of slices to send: Send
Hi folks,

I was working on a application which gets a XML file as input which i am going to parse using SAX parser. In my code i have defined lot of variables (around 60 to 70 String objects) in the fashion shown below



as you can see all these objects are final which i am going to use it for String equality check condition. I am getting worried about the amount of memory these String objects consume. Is there a better way of doing the same thing?
+Pie Number of slices to send: Send
 


I am getting worried about the amount of memory these String objects consume.


Why? Are you seeing performance issues with your applications? Do you have a very constrained deployment environment?


Is there a better way of doing the same thing?


I'm guessing these variables match the elements you need to parse? If this is the case, no. You need the have the element name in order to match it.
+Pie Number of slices to send: Send
 


Why? Are you seeing performance issues with your applications? Do you have a very constrained deployment environment?



Yes, it takes some time to finish parsing the XML file.
To be more clear i am generating my application GUI based on the XML file and after parsing through the file then only i am able to get the GUI which requires some time.


I'm guessing these variables match the elements you need to parse? If this is the case, no. You need the have the element name in order to match it.



Yes i am using those variables for that purpose while parsing.
+Pie Number of slices to send: Send
Parsing XML files can be slow. Its unlikely it is your use of these String variables that is the cause is though. It is also unlikely that memory is the constraint. If it were, you might start to see OutOfMemoryErrors. My guess is the bottleneck is the CPU.

There is a general rule for Swing applications, do not do lengthy non-GUI work on the event-dispatch thread. Do you need to use or show your entire XML model when you start your application, or can you use SwingUtilities to improve the responsiveness of the GUI?
+Pie Number of slices to send: Send
It's better use SAX parser API ,where every method which is required to parse XML file has given. That will be helpful.
+Pie Number of slices to send: Send
 

Originally posted by mintoo kumar:
It's better use SAX parser API ,where every method which is required to parse XML file has given. That will be helpful.



Balasubramanian Chandrasekaran is using a SAX parser.
+Pie Number of slices to send: Send
my focus was like

origina post code:
--------------------------------------------------------------------------------

public static final String STARTING_TAG = "start";public static final String ELEMENT_START_TAG = "element";...............public static final String ENDING_TAG = "end";

--------------------------------------------------------------------------------

rather using these elements use the methods and all the facility avliable in SAX parser API.

Hope i made the point correctly.
+Pie Number of slices to send: Send
Not sure I follow. My assumption is Balasubramanian Chandrasekaran is using these values to work out what to do with an element when the Handler's startElement method is fired. What SAX API methods do you mean?
+Pie Number of slices to send: Send
Paul you are correct, I use those String object for equality check.

My scenario is:
1. I will check whether i got my application starting tag by checking the parsed value to my STARTING_TAG object if that matches i will be doing relevant operations like constructing a new JFrame which will get all the components.
2. Then i will again check the equality condition on parsed value with my ELEMENT_START_TAG and then i will check what is that type of element and construct the relevant component onto the JFrame which i created previously.

....... Likewise it goes.

And can you please explain in detail.What you mean by


Do you need to use or show your entire XML model when you start your application, or can you use SwingUtilities to improve the responsiveness of the GUI?



Regarding Mintoo Kumar reply,


rather using these elements use the methods and all the facility avliable in SAX parser API.


I don't get what you are trying to convey?


After Displaying my JFrame i am calling


Whether this will guarantee Garbage Collection on my String objects??
[ May 13, 2008: Message edited by: Balasubramanian Chandrasekaran ]
Oh, sure, you could do that. Or you could eat some pie. While reading this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1201 times.
Similar Threads
String Objects
Interface Concept
Basic concept for memory allocation
final variable
final variable initialisation(simple code)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:34:01.