reducing no: of objects created, to improve performance...
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
reducing no: of objects created, to improve performance...
with the original code being the following, can i reduce the no: of times that objects(GifFileSelector objects..) are created in the method 'open()' by using the coding that i have put below???
The objects are not created within a for loop continuously.. so i'm not sure if i can make any change to 'reuse objects'.. (provided this open() method is called several times)
original :
Code:
public class FileMenu extends AbstractMenu
{
public final int INDEX = 0;
private static final String TITLE = "File";
private static final int MNEMONIC = KeyEvent.VK_F;
..........
public void itemSelected(String itemName)
{
if (itemName.equals(MENU_ITEMS[0].getName()))
open();
.......
}
private void open()
{
GifFileSelector g = new GifFileSelector();
.........
}
The changes that i made:
Code:
public class FileMenu extends AbstractMenu
{
public final int INDEX = 0;
private static final String TITLE = "File";
private static final int MNEMONIC = KeyEvent.VK_F;
GifFileSelector g; //creating GifFileSelector instance
...............
private void open()
{
if (g == NULL)
{
g = new GifFileSelector();
}
int selected = g.showOpenDialog(MDIFrame.getDesktop());
if (selected == JFileChooser.APPROVE_OPTION)
{
try
{
.........
}
}
}
so does that mean, that i 'm not making any difference(performance improvement) at all to the code, provided the open method is called more than once???
i mean if the open method is called (more than one picture is being opened at different times) am i not reducing the no: of objects being created ..?
so does that mean, that i 'm not making any difference(performance improvement) at all to the code, provided the open method is called more than once???
i mean if the open method is called (more than one picture is being opened at different times) am i not reducing the no: of objects being created ..?
i said yes in reponse to
Quote:
with the original code being the following, can i reduce the no: of times that objects(GifFileSelector objects..) are created in the method 'open()' by using the coding that i have put below???
okay.. thanks!
well need a lil clarification... If this particular open() method is called only 'once' , both the original coding and my code will do the same thing , ya?
Since, in the modified code that i put, 'g' will be equal to NULL, the object will be created for the first time ya?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.