aspose file tools*
The moose likes Performance and the fly likes Creating bajillions of little objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Creating bajillions of little objects" Watch "Creating bajillions of little objects" New topic
Author

Creating bajillions of little objects

Josiah Haswell
Greenhorn

Joined: Jun 13, 2007
Posts: 3
Hey ranchers!

I need to create a grid of JXImagePanels (basically little JPanels that are easy to add images to), but the grid has to potentially contain many thousands of these. They're small enough that I can get about 30,000 of them out of a 10MB heap space when I instantiate them normally, but I suspect there's a better way to make a grid.

When they're all created, they're all the same and none of them are ever "reused" so I didn't think this would be an appropriate use of the flyweight pattern. Would anyone be able to recommend a solution?

Thanks!

Joe
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

JTable, JList, JTree, etc, use just one (or, if customized) just a few components to draw all their cells. It's a very memory-efficient system, and very performant as well. There's a model that holds the data, and whenever the table/list/tree needs to draw a cell, it configures the single "cell renderer" with the appropriate data, lets it draw itself in the right place, and then removes it. Does this make sense for your application?


[Jess in Action][AskingGoodQuestions]
Josiah Haswell
Greenhorn

Joined: Jun 13, 2007
Posts: 3
I hadn't thought of that, lemme give it a try!

Thanks!

Joe
Josiah Haswell
Greenhorn

Joined: Jun 13, 2007
Posts: 3
This works perfectly, it was just the hint I was looking for!

Thanks!

Joe
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating bajillions of little objects