JVM out of memory (I want to solve this with out increasing the heap size)
public ThreeVec findVec(double[] pix_lab,double[][] graphic_labs){
ThreeVec result = new ThreeVec();
Vector<Double> diff = new Vector<Double>();
Vector<Double> tempdiff = new Vector<Double>();
double d1,d2,d3;
for(int i=0;i<graphic_labs.length;i++){
d1 = graphic_labs[0]-pix_lab[0];
d2 = graphic_labs[i][1]-pix_lab[1];
d3 = graphic_labs[i][2]-pix_lab[2];
diff.add(Math.sqrt((d1*d1)+(d2*d2)+(d3*d3)));
tempdiff.add(Math.sqrt((d1*d1)+(d2*d2)+(d3*d3)));
Collections.sort(tempdiff);
int[] vecIdx = new int[3];
vecIdx[0] = diff.indexOf(tempdiff.elementAt(0));
vecIdx[1] = diff.indexOf(tempdiff.elementAt(1));
vecIdx[2] = diff.indexOf(tempdiff.elementAt(2));
double[][] vecs = new double[3][3];
vecs[0][0] = (graphic_labs[vecIdx[0]][0]);
vecs[0][1] = (graphic_labs[vecIdx[0]][1]);
vecs[0][2] = (graphic_labs[vecIdx[0]][2]);
vecs[1][0] = (graphic_labs[vecIdx[1]][0]);
vecs[1][1] = (graphic_labs[vecIdx[1]][1]);
vecs[1][2] = (graphic_labs[vecIdx[1]][2]);
vecs[2][0] = (graphic_labs[vecIdx[2]][0]);
vecs[2][1] = (graphic_labs[vecIdx[2]][1]);
vecs[2][2] = (graphic_labs[vecIdx[2]][2]);
Matrix vec_matrix = new Matrix(vecs);
Matrix vec_mat_inv = vec_matrix.inverse();
Matrix pix_matrix = new Matrix(1,3);
pix_matrix.set(0,0,pix_lab[0]);
pix_matrix.set(0,1,pix_lab[1]);
pix_matrix.set(0,2,pix_lab[2]);
Matrix abc = pix_matrix.times(vec_mat_inv);
result.setVecIdx(vecIdx);
result.setABC(abc);
return result;
Matrix is the class defined in JAMA library.
I am getting OutOfMemoryError in this method.
Let me explain. The above method is called from a nested 'for' loop something like the pseudocode below.
BufferedImage in_graphic = ImageIO.read(graphic);
for(int j=0;j<in_graphic.getHeight();j++){
for(int i=0;i<in_graphic.getWidth();i++){
findVec(param1,param2);
lengths of param1 and param2 are fixed
param1's length is always 3
param2.length is 8 and param2[i] is 3
I thought that this code is independent of image size but it not. As the image size increases beyond a certain size I am getting OutOfMemoryError. I dont know why am I doing something wrong here. Thanks in advance.
I know you asked about a memory issue, not a speed issue. But, another slight speed-up would be to compute the square root once, and then put it in both lists:
diff.add(Math.sqrt((d1*d1)+(d2*d2)+(d3*d3)));
tempdiff.add(Math.sqrt((d1*d1)+(d2*d2)+(d3*d3)));could be:
Double distance = Double.valueOf(Math.sqrt((d1*d1)+(d2*d2)+(d3*d3)));
diff.add(distance);
tempdiff.add(distance);That not only speeds it up (fewer calculations), but it creates half as many Double objects as your way was creating.
Autoboxing is slowing you down, too. (The use of Double and the autoboxing will go away if you use ejp's suggestion to use arrays of double. But, you could still compute that value only once.)
Your Vector<Double> are local variables, anyway. If I'm reading your code correctly, they are each only 8 elements long. If so, that's not the main memory issue. Using an array of double primitives will use a little less memory and will be faster, but I don't think the Vector<Double> is the biggest issue. You aren't storing the references to those Vectors anywhere, so they will be eligible for garbage collection at the end of the method.
So, I know you said it was pseudocode, but your pseudocode as to how findVec was called didn't even use the return value (the ThreeVec that the method creates). Maybe if you explain better what param1 and param2 are (how they are calculated based on height and width, or other useful information), someone could give you a better suggestion. Also, what's a ThreeVec, anyway?
Maybe try posting the actual code for your loop, instead of pseudocode. Use the CODE button (above the posting box) to format your code nicely.
Similar Messages
-
[Solved] Seeking solution to increase the font size in a base install
I recently installed Arch onto a machine with the following hardware/software
i686 AMD Semprom 3600+
ATI Radeon RS690 [X1200 series]
NEC Multisync E1100+ monitor
xf86-video-ati video driver
Kernel 2.6.37-ARCH
It works nicely. That is not the problem - I cannot see well enough to read the very tiny console font.
I tried grub VGA setting but as soon as UDEV got hold of the machine the font went small again.
I tried setfont -h## but I probably do not know enough about that from reading the man page to
correctly set the font.
I would like to have a larger font size - that is make an "m" triple or double it's default size.
I have tried to puzzle through the boot process but can't seem to get a handle on a good way,
or any way to change this. I am having problems getting the menus to work in xorg and need to
use the command line to fix the problems.
Any pointers would be appreciated.
Thanks
algernon
Last edited by algernon (2011-02-19 11:09:44)Have you tried https://wiki.archlinux.org/index.php/KM … e_too_tiny
-
i cant fifure this out...who wants to solve a huge crime network..thisa is no joke
Nope. That's the issue.
They'll sync on a third device acting as a hotspot, but the device sending a signal is not "on" the network it creates so the airport is all by itself on that network. At least that is what it looks like to me. Anyone have another take on it? Seems pretty silly that an iPad can put out a wifi signal, an Airport Express can receive a wifi signal, and yet there is no simple way to get them to communicate under this particular condition. -
I have an itunes account on my home PC. I want to use my same account but on my laptop. How do i do this with out wiping out my phone and backing up all my Pictures and Apps? Please Help.
Copy everything from the old computer or your backup copy of your old computer to your new one.
Type "move itunes library from pc to mac" or similar into the google search bar. -
Is there a way to increase the icon size (and the text below) without using zoom in iOS 7? I am trying to help out someone who has moderate visual impairment that does not want to use zoom just to see the icons and their labels.
Hello Apple.
It seems you have gone to great lengths to improve accessibility in many areas of the iPad. Why was this obvious problem with icon text size missed? (It's not with the Mac.). And for so long too.
Do you employ people with actual accessibility problems to help you do UI design?
I think too, that some buttons are too close for people who might have motor control problems.
I love my iPad but I fear as I age, the iPad might not keep up with me. -
I have two macs at my house, and multiple iPhones. I want to keep the same apple id as everyone else, but i want to put my own music only on my iPhone. I want to do this with my laptop which is not the family's main iTune's computer.
If you use the same Apple ID for iCloud on each device, yes. However, you can use the same Apple ID for iTunes content on each device, but different Apple ID's for iCloud, iMessage, FaceTime, etc., on each device. That way, you can have whatever iTunes content you want on each phone, but keep all of the other data separate. You can create another Apple ID here:
https://appleid.apple.com/cgi-bin/WebObjects/MyAppleId.woa/wa/createAppleId?loca lang=en_US
Must be a verified email address. -
How can I increase the font size of my email when I print it out, it is printing tiny
How can I increase the font size when I print out emails, it is printing tiny size?
In the Print dialog window, click the small reveal-button to the right of the printer's name -
The window will expand to show additional settings (similar to 'old' Page Setup) -
Be sure "Scale:" is set to 100% and the 'Keep apparent font size' item is checked. -
How can I sign out of my apple account on my iPhone with out erasing everything
How can I sign out of my apple account on my iPhone with out erasing everything
I meant apple ID
-
Calendar and Time showing in arabic but my phone's language is English. I bought my phone from DU in UAE , Dubai. Please help me solve this issue while keeping the Region to United Arab Emirates
Valentine350z wrote:
while keeping the Region to United Arab Emirates
Not possible, I think. Tell Apple how you feel about this at
http://www.apple.com/feedback/iphone.html -
what if the user also forgot ps apple? how to solve this problem? whether the iPhone can still be used?
Start here:
https://iforgot.apple.com -
I want to purchase an ipad 32gb in the larger size buy have read many bad reviews that they have problems staying connected to wifi. I don't want to have to buy a data package so I only want the wifi one. I already pay apple for my iphone data and I can't afford more money. Why are there so many bad reviews and are the newer ones that much better, according to many reviews they are not.Please help
I already pay apple for my iphone data
You pay your carrier for data, not Apple.
Why are there so many bad reviews
Where? Regardless, there are always going to be a handful of people having some sort of issue with any given device, but I would not therefore assume that you would be one of them. -
When trying to open lightroom I get a message that says, "The lightroom.exe that the short cut refers to has been changed or moved, so the short cut will no longer work properly. Do you want to remove this short cut? The program has opened and worked fine in the past.
You have (probably accidentally) moved or deleted the Lightroom program. You need to find it (have your operating system search for lightroom.exe) and move it back to where the shortcut expects it to be.
-
I want to print iCal with Mondays in the left hand side column. My calendar prints with Tuesday in the left hand column even though it displays Mondays in the left hand column when in normal use.
Thank you for your advice, it works. I have struggled for hours to find the solution I am very grateful.
-
last time i bought apps by using visa gift card so iam trying to use the kind of visa gift card and the system is denying the method payment ....any idea how to solve this with my itune account ?
A few reasons I can think of, but instead of shooting in the dark, lets check with experts who can look at your account.
iTunes Store Support
http://www.apple.com/emea/support/itunes/contact.html -
i need to get one of my older iphones (my wifes) assing to me in my name . Can i do this with out loosing all the apps and contacts on it?
Use your backup copy of your old computer to put everything on your new computer, then sync the iphone to that comptuer.
Maybe you are looking for
-
Adobe Premiere 6.0 and Windows 7
OK Folks Don't laugh but has anyone tried to install good old Premiere 6.0 on a PC that is running Windows 7? I would appreciate any advice - even "it simply will not work" LoL Many thanks Brian Emmis
-
Imessage down on my iPhone: "the person cannot be reached by imessage at this time"
My internet connection works and I can send emails from my phone. Additionally I can send imessages from my macbook. But I can't send imessages from my iphone. It either doesn't recognize certain phones as having imsg (when i know that they do) and t
-
I am facing some problems with managing the local storage of my iPad !!
SO i wanted to download asphalt 7 on my iPad 16gb with 1.9gb left ! And the size of the game is 1.27gb but when i tried to install it, a message appeared saying that THERE IS NOT ENOUGH LOCAL STORAGE TO DOWNLOAD ASPHALT 7 HEAT !! so i went to Settin
-
I sold my macbook and i want to restore it clean i want know to do it.
I sold my macbook pro and i want to restore it clean may someone know how to do this.
-
Issue of Outgoing payment F-53
I have a problem about document currency. Actually, our PO, GR/IR is based on USD currency. But when we did clearing by F-53, we use our local currency for document currency. I would like to know is better to use USD as document currency or local cur