Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: VisualVM: Monitoring the Images instances being loaded that causes Java Heap Space

  1. #1
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default VisualVM: Monitoring the Images instances being loaded that causes Java Heap Space

    same part of the program i was creating, i have tons of images that is being loaded in the game, JPEGs and PNGs, each of them has a dimension of 1000x500,

    this is the class that loads the images, it doesnt run, i just want to show, how many images that i needed to load for the game to run as i programmed it to be
    import java.awt.Image;
    import java.util.HashMap;
    import java.util.Map;
    import javax.swing.ImageIcon;
     
    /**
     *
     * @author Zabdiel
     */
    public class WorldZoo {
     
        private static Map<String, Map<Integer, Image>> worldZoo;
     
        public static void initWorldZoo() {
     
            worldZoo = new HashMap<String, Map<Integer, Image>>();
     
            Map<Integer, Image> northAmericanZoo = new HashMap<Integer, Image>();
            Map<Integer, Image> southAmericanZoo = new HashMap<Integer, Image>();
            Map<Integer, Image> europeanZoo = new HashMap<Integer, Image>();
            Map<Integer, Image> africanZoo = new HashMap<Integer, Image>();
            Map<Integer, Image> asianZoo = new HashMap<Integer, Image>();
            Map<Integer, Image> australianZoo = new HashMap<Integer, Image>();
            Map<Integer, Image> antarcticanZoo = new HashMap<Integer, Image>();
     
            // north american animals
            Image antelope = getImageIcon("textQuiz7Continents/images/animalCaptured/northAmerica/antelope.png").getImage();
            Image armadillo = getImageIcon("textQuiz7Continents/images/animalCaptured/northAmerica/armadillo.png").getImage();
            Image avocet = getImageIcon("textQuiz7Continents/images/animalCaptured/northAmerica/avocet.jpg").getImage();
            Image barnOwl = getImageIcon("textQuiz7Continents/images/animalCaptured/northAmerica/barnOwl.jpg").getImage();
            Image blackWidowSpider = getImageIcon("textQuiz7Continents/images/animalCaptured/northAmerica/blackWidowSpider.jpg").getImage();
            Image gilaMonster = getImageIcon("textQuiz7Continents/images/animalCaptured/northAmerica/gilaMonster.png").getImage();
            Image lynx = getImageIcon("textQuiz7Continents/images/animalCaptured/northAmerica/lynx.jpg").getImage();
            Image moleAmerica = getImageIcon("textQuiz7Continents/images/animalCaptured/northAmerica/mole.jpg").getImage();
            Image opossum = getImageIcon("textQuiz7Continents/images/animalCaptured/northAmerica/opossums.png").getImage();
            Image pika = getImageIcon("textQuiz7Continents/images/animalCaptured/northAmerica/pika.jpg").getImage();
            Image puffin = getImageIcon("textQuiz7Continents/images/animalCaptured/northAmerica/puffin.jpg").getImage();
            Image raccoon = getImageIcon("textQuiz7Continents/images/animalCaptured/northAmerica/raccoon.jpg").getImage();
            Image robin = getImageIcon("textQuiz7Continents/images/animalCaptured/northAmerica/robin.jpg").getImage();
            Image skunk = getImageIcon("textQuiz7Continents/images/animalCaptured/northAmerica/skunk.png").getImage();
            Image spadeFootToad = getImageIcon("textQuiz7Continents/images/animalCaptured/northAmerica/spadeFootToad.jpg").getImage();
            Image stickInsect = getImageIcon("textQuiz7Continents/images/animalCaptured/northAmerica/stickInsect.jpg").getImage();
            Image weasel = getImageIcon("textQuiz7Continents/images/animalCaptured/northAmerica/weasel.png").getImage();
            Image wolverine = getImageIcon("textQuiz7Continents/images/animalCaptured/northAmerica/wolverine.jpg").getImage();
     
            northAmericanZoo.put(1, antelope);
            northAmericanZoo.put(2, armadillo);
            northAmericanZoo.put(3, avocet);
            northAmericanZoo.put(4, barnOwl);
            northAmericanZoo.put(5, blackWidowSpider);
            northAmericanZoo.put(6, gilaMonster);
            northAmericanZoo.put(7, lynx);
            northAmericanZoo.put(8, moleAmerica);
            northAmericanZoo.put(9, opossum);
            northAmericanZoo.put(10, pika);
            northAmericanZoo.put(11, puffin);
            northAmericanZoo.put(12, raccoon);
            northAmericanZoo.put(13, robin);
            northAmericanZoo.put(14, skunk);
            northAmericanZoo.put(15, spadeFootToad);
            northAmericanZoo.put(16, stickInsect);
            northAmericanZoo.put(17, weasel);
            northAmericanZoo.put(18, wolverine);
     
            // northAmericanZoo. put 1 or 2 more for North America
            worldZoo.put("North America", northAmericanZoo);
     
            // south american animals
            Image amazonManatee = getImageIcon("textQuiz7Continents/images/animalCaptured/southAmerica/amazonManatee.png").getImage();
            Image andeanCat = getImageIcon("textQuiz7Continents/images/animalCaptured/southAmerica/andeanCat.png").getImage();
            Image baldUakari = getImageIcon("textQuiz7Continents/images/animalCaptured/southAmerica/baldUakari.png").getImage();
            Image chinchillas = getImageIcon("textQuiz7Continents/images/animalCaptured/southAmerica/chinchillas.png").getImage();
            Image giantArmadillo = getImageIcon("textQuiz7Continents/images/animalCaptured/southAmerica/giantArmadillo.png").getImage();
            Image giantOtter = getImageIcon("textQuiz7Continents/images/animalCaptured/southAmerica/giantOtter.png").getImage();
            Image goldenLionTamarin = getImageIcon("textQuiz7Continents/images/animalCaptured/southAmerica/goldenLionTamarin.png").getImage();
            Image littleSpottedCat = getImageIcon("textQuiz7Continents/images/animalCaptured/southAmerica/littleSpottedCat.png").getImage();
            Image manedWolf = getImageIcon("textQuiz7Continents/images/animalCaptured/southAmerica/manedWolf.png").getImage();
            Image mantledHowlerMonkey = getImageIcon("textQuiz7Continents/images/animalCaptured/southAmerica/mantledHowlerMonkey.png").getImage();
            Image margay = getImageIcon("textQuiz7Continents/images/animalCaptured/southAmerica/margay.png").getImage();
            Image ocelot = getImageIcon("textQuiz7Continents/images/animalCaptured/southAmerica/ocelot.png").getImage();
            Image thinSpinedPorcupine = getImageIcon("textQuiz7Continents/images/animalCaptured/southAmerica/thinSpinedPorcupine.png").getImage();
            Image yellowTailedWoolMonkey = getImageIcon("textQuiz7Continents/images/animalCaptured/southAmerica/yellowTailedWoollyMonkey.png").getImage();
     
            southAmericanZoo.put(1, amazonManatee);
            southAmericanZoo.put(2, andeanCat);
            southAmericanZoo.put(3, baldUakari);
            southAmericanZoo.put(4, chinchillas);
            southAmericanZoo.put(5, giantArmadillo);
            southAmericanZoo.put(6, giantOtter);
            southAmericanZoo.put(7, goldenLionTamarin);
            southAmericanZoo.put(8, littleSpottedCat);
            southAmericanZoo.put(9, manedWolf);
            southAmericanZoo.put(10, mantledHowlerMonkey);
            southAmericanZoo.put(11, margay);
            southAmericanZoo.put(12, ocelot);
            southAmericanZoo.put(13, thinSpinedPorcupine);
            southAmericanZoo.put(14, yellowTailedWoolMonkey);
            worldZoo.put("South America", southAmericanZoo);
     
            // european animals
            Image dourmouse = getImageIcon("textQuiz7Continents/images/animalCaptured/europe/dourmouse.png").getImage();
            Image badger = getImageIcon("textQuiz7Continents/images/animalCaptured/europe/europeanBadger.png").getImage();
            Image beaver = getImageIcon("textQuiz7Continents/images/animalCaptured/europe/europeanBeaver.png").getImage();
            Image hedgehog = getImageIcon("textQuiz7Continents/images/animalCaptured/europe/europeanHedgehog.png").getImage();
            Image moleEurope = getImageIcon("textQuiz7Continents/images/animalCaptured/europe/europeanMole.png").getImage();
            Image otter = getImageIcon("textQuiz7Continents/images/animalCaptured/europe/europeanOtter.png").getImage();
            Image pineMarten = getImageIcon("textQuiz7Continents/images/animalCaptured/europe/europeanPineMarten.png").getImage();
            Image poleCat = getImageIcon("textQuiz7Continents/images/animalCaptured/europe/europeanPoleCat.png").getImage();
            Image redFox = getImageIcon("textQuiz7Continents/images/animalCaptured/europe/europeanRedfox.png").getImage();
            Image waterVole = getImageIcon("textQuiz7Continents/images/animalCaptured/europe/europeanWaterVole.png").getImage();
            Image mustelidae = getImageIcon("textQuiz7Continents/images/animalCaptured/europe/mustelidae.png").getImage();
            Image sable = getImageIcon("textQuiz7Continents/images/animalCaptured/europe/sable.png").getImage();
            Image seal = getImageIcon("textQuiz7Continents/images/animalCaptured/europe/seal.png").getImage();
            Image stoat = getImageIcon("textQuiz7Continents/images/animalCaptured/europe/stoat.png").getImage();
            Image woodMouse = getImageIcon("textQuiz7Continents/images/animalCaptured/europe/woodMouse.png").getImage();
     
            europeanZoo.put(1, dourmouse);
            europeanZoo.put(2, badger);
            europeanZoo.put(3, beaver);
            europeanZoo.put(4, hedgehog);
            europeanZoo.put(5, moleEurope);
            europeanZoo.put(6, otter);
            europeanZoo.put(7, pineMarten);
            europeanZoo.put(8, poleCat);
            europeanZoo.put(9, redFox);
            europeanZoo.put(10, waterVole);
            europeanZoo.put(11, mustelidae);
            europeanZoo.put(12, sable);
            europeanZoo.put(13, seal);
            europeanZoo.put(14, stoat);
            europeanZoo.put(15, woodMouse);
            worldZoo.put("Europe", europeanZoo);
     
     
            // african animals
            Image africanWildDog = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/africanWildDog.png").getImage();
            Image antEater = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/antEater.png").getImage();
            Image ayeaye = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/ayeaye.png").getImage();
            Image bongo = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/bongo.png").getImage();
            Image caracal = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/caracal.png").getImage();
            Image clawedFrog = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/clawedFrog.png").getImage();
            Image earwig = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/earwig.png").getImage();
            Image fennec = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/fennec.png").getImage();
            Image fossa = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/fossa.png").getImage();
            Image gerbil = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/gerbil.png").getImage();
            Image giantAfricanSnail = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/giantAfricanSnail.png").getImage();
            Image guinea = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/guinea.png").getImage();
            Image heron = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/heron.png").getImage();
            Image hyena = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/hyena.png").getImage();
            Image ibis = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/ibis.png").getImage();
            Image impala = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/impala.png").getImage();
            Image kudu = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/kudu.png").getImage();
            Image laybird = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/laybird.png").getImage();
            Image leafTailedGeco = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/leafTailedGeco.png").getImage();
            Image leopardTortoise = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/leopardTortoise.png").getImage();
            Image mayfly = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/mayfly.png").getImage();
            Image meerkat = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/meerkat.png").getImage();
            Image moorhen = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/moorhen.png").getImage();
            Image mule = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/mule.png").getImage();
            Image nightingale = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/nightingale.png").getImage();
            Image okapi = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/okapi.png").getImage();
            Image palmCivert = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/palmCivert.png").getImage();
            Image panther = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/panther.png").getImage();
            Image patas = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/patas.png").getImage();
            Image pheasant = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/pheasant.png").getImage();
            Image pussMoth = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/pussMoth.png").getImage();
            Image pygmyHippopotamus = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/pygmyHippopotamus.png").getImage();
            Image radiatedTortoise = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/radiatedTortoise.png").getImage();
            Image riverTurtle = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/riverTurtle.png").getImage();
            Image rockhyrax = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/rockhyrax.png").getImage();
            Image serval = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/serval.png").getImage();
            Image sparrow = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/sparrow.png").getImage();
            Image termite = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/termite.png").getImage();
            Image treeFrog = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/treeFrog.png").getImage();
            Image waterBuffalo = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/waterBuffalo.png").getImage();
            Image wildebeest = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/wildebeest.png").getImage();
            Image woodlouse = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/woodlouse.png").getImage();
            Image zebu = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/zebu.png").getImage();
            Image zonkey = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/zonkey.png").getImage();
            Image zorse = getImageIcon("textQuiz7Continents/images/animalCaptured/africa/zorse.png").getImage();
     
            africanZoo.put(1, africanWildDog);
            africanZoo.put(2, antEater);
            africanZoo.put(3, ayeaye);
            africanZoo.put(4, bongo);
            africanZoo.put(5, caracal);
            africanZoo.put(6, clawedFrog);
            africanZoo.put(7, earwig);
            africanZoo.put(8, fennec);
            africanZoo.put(9, fossa);
            africanZoo.put(10, gerbil);
            africanZoo.put(11, giantAfricanSnail);
            africanZoo.put(12, guinea);
            africanZoo.put(13, heron);
            africanZoo.put(14, hyena);
            africanZoo.put(15, ibis);
            africanZoo.put(16, impala);
            africanZoo.put(17, kudu);
            africanZoo.put(18, laybird);
            africanZoo.put(19, leafTailedGeco);
            africanZoo.put(20, leopardTortoise);
            africanZoo.put(21, mayfly);
            africanZoo.put(22, meerkat);
            africanZoo.put(23, moorhen);
            africanZoo.put(23, mule);
            africanZoo.put(24, nightingale);
            africanZoo.put(25, okapi);
            africanZoo.put(26, palmCivert);
            africanZoo.put(27, panther);
            africanZoo.put(28, patas);
            africanZoo.put(29, pheasant);
            africanZoo.put(30, pussMoth);
            africanZoo.put(31, pygmyHippopotamus);
            africanZoo.put(32, radiatedTortoise);
            africanZoo.put(33, riverTurtle);
            africanZoo.put(34, rockhyrax);
            africanZoo.put(35, serval);
            africanZoo.put(36, sparrow);
            africanZoo.put(37, termite);
            africanZoo.put(38, treeFrog);
            africanZoo.put(39, waterBuffalo);
            africanZoo.put(40, wildebeest);
            africanZoo.put(41, woodlouse);
            africanZoo.put(42, zebu);
            africanZoo.put(43, zonkey);
            africanZoo.put(44, zorse);
            worldZoo.put("Africa", africanZoo);
     
     
     
            Image antEaters = getImageIcon("textQuiz7Continents/images/animalCaptured/asia/antEaters.png").getImage();
            Image binturong = getImageIcon("textQuiz7Continents/images/animalCaptured/asia/binturong.png").getImage();
            Image cloudedLeopard = getImageIcon("textQuiz7Continents/images/animalCaptured/asia/cloudedLeopard.png").getImage();
            Image commonBuzzard = getImageIcon("textQuiz7Continents/images/animalCaptured/asia/commonBuzzard.jpg").getImage();
            Image crane = getImageIcon("textQuiz7Continents/images/animalCaptured/asia/crane.png").getImage();
            Image gharial = getImageIcon("textQuiz7Continents/images/animalCaptured/asia/gharial.png").getImage();
            Image llamas = getImageIcon("textQuiz7Continents/images/animalCaptured/asia/llamas.png").getImage();
            Image moongose = getImageIcon("textQuiz7Continents/images/animalCaptured/asia/moongose.png").getImage();
            Image porcupine = getImageIcon("textQuiz7Continents/images/animalCaptured/asia/porcupine.png").getImage();
            Image uguitsu = getImageIcon("textQuiz7Continents/images/animalCaptured/asia/uguitsu.png").getImage();
            Image vulture = getImageIcon("textQuiz7Continents/images/animalCaptured/asia/vulture.png").getImage();
            Image yak = getImageIcon("textQuiz7Continents/images/animalCaptured/asia/yak.png").getImage();
     
            asianZoo.put(1, antEaters);
            asianZoo.put(2, binturong);
            asianZoo.put(3, cloudedLeopard);
            asianZoo.put(4, commonBuzzard);
            asianZoo.put(5, crane);
            asianZoo.put(6, gharial);
            asianZoo.put(7, llamas);
            asianZoo.put(8, moongose);
            asianZoo.put(9, porcupine);
            asianZoo.put(10, uguitsu);
            asianZoo.put(11, vulture);
            asianZoo.put(12, yak);
            worldZoo.put("Asia", asianZoo);
     
            Image easternBarredBandicoot = getImageIcon("textQuiz7Continents/images/animalCaptured/australia/easternBarredBandicoot.jpg").getImage();
            Image echidna = getImageIcon("textQuiz7Continents/images/animalCaptured/australia/echidna.jpg").getImage();
            Image frilledLizard = getImageIcon("textQuiz7Continents/images/animalCaptured/australia/frilledLizard.jpg").getImage();
            Image gouldianFinch = getImageIcon("textQuiz7Continents/images/animalCaptured/australia/gouldianFinch.jpg").getImage();
            Image greaterBilby = getImageIcon("textQuiz7Continents/images/animalCaptured/australia/greaterBilby.jpg").getImage();
            Image leadBeaters = getImageIcon("textQuiz7Continents/images/animalCaptured/australia/leadBeaters.jpg").getImage();
            Image lumholtzTreeKangaroo = getImageIcon("textQuiz7Continents/images/animalCaptured/australia/lumholtzTreeKangaroo.jpg").getImage();
            Image redTaild = getImageIcon("textQuiz7Continents/images/animalCaptured/australia/redTailed.jpg").getImage();
            Image thylacine = getImageIcon("textQuiz7Continents/images/animalCaptured/australia/thylacine.jpg").getImage();
            Image wombats = getImageIcon("textQuiz7Continents/images/animalCaptured/australia/wombats.jpg").getImage();
     
            australianZoo.put(1, easternBarredBandicoot);
            australianZoo.put(2, echidna);
            australianZoo.put(3, frilledLizard);
            australianZoo.put(4, gouldianFinch);
            australianZoo.put(5, greaterBilby);
            australianZoo.put(6, leadBeaters);
            australianZoo.put(7, lumholtzTreeKangaroo);
            australianZoo.put(8, redTaild);
            australianZoo.put(9, thylacine);
            australianZoo.put(10, wombats);
            worldZoo.put("Australia", australianZoo);
     
            Image combJelly = getImageIcon("textQuiz7Continents/images/animalCaptured/antarctica/combJelly.jpg").getImage();
            Image diplulmaris = getImageIcon("textQuiz7Continents/images/animalCaptured/antarctica/diplulmaris.jpg").getImage();
            Image duncecap = getImageIcon("textQuiz7Continents/images/animalCaptured/antarctica/duncecap.jpg").getImage();
            Image flowerHatJelly = getImageIcon("textQuiz7Continents/images/animalCaptured/antarctica/flowerHatJelly.jpg").getImage();
            Image marineWorm = getImageIcon("textQuiz7Continents/images/animalCaptured/antarctica/marineWorm.jpg").getImage();
            Image sandHopper = getImageIcon("textQuiz7Continents/images/animalCaptured/antarctica/sandHopper.jpg").getImage();
            Image scaleWorm = getImageIcon("textQuiz7Continents/images/animalCaptured/antarctica/scaleWorm.jpg").getImage();
            Image scyphomedusa = getImageIcon("textQuiz7Continents/images/animalCaptured/antarctica/scyphomedusa.jpg").getImage();
            Image seaPig = getImageIcon("textQuiz7Continents/images/animalCaptured/antarctica/seaPig.jpg").getImage();
            Image southernRightWhale = getImageIcon("textQuiz7Continents/images/animalCaptured/antarctica/southernRightWhale.jpg").getImage();
            Image yetiCrab = getImageIcon("textQuiz7Continents/images/animalCaptured/antarctica/yetiCrab.jpg").getImage();
     
            antarcticanZoo.put(1, combJelly);
            antarcticanZoo.put(2, diplulmaris);
            antarcticanZoo.put(3, duncecap);
            antarcticanZoo.put(4, flowerHatJelly);
            antarcticanZoo.put(5, marineWorm);
            antarcticanZoo.put(6, sandHopper);
            antarcticanZoo.put(7, scaleWorm);
            antarcticanZoo.put(8, scyphomedusa);
            antarcticanZoo.put(9, seaPig);
            antarcticanZoo.put(10, southernRightWhale);
            antarcticanZoo.put(11, yetiCrab);
            worldZoo.put("Antarctica", antarcticanZoo);
        }
    }

    as i run the program, when this class loads all the images, a part of the program shows this error
    Exception in thread "Image Fetcher 1" java.lang.OutOfMemoryError: Java heap space
    	at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:41)
    	at java.awt.image.Raster.createPackedRaster(Raster.java:458)
    	at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1015)
    	at sun.awt.image.ImageRepresentation.createBufferedImage(ImageRepresentation.java:230)
    	at sun.awt.image.ImageRepresentation.setPixels(ImageRepresentation.java:528)
    	at sun.awt.image.ImageDecoder.setPixels(ImageDecoder.java:120)
    	at sun.awt.image.PNGImageDecoder.sendPixels(PNGImageDecoder.java:531)
    	at sun.awt.image.PNGImageDecoder.produceImage(PNGImageDecoder.java:452)
    	at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:246)
    	at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172)
    	at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)
    Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space
    	at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:41)
    	at java.awt.image.Raster.createPackedRaster(Raster.java:458)
    	at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1015)
    	at sun.awt.image.ImageRepresentation.createBufferedImage(ImageRepresentation.java:230)
    	at sun.awt.image.ImageRepresentation.setPixels(ImageRepresentation.java:528)
    	at sun.awt.image.ImageDecoder.setPixels(ImageDecoder.java:120)
    	at sun.awt.image.PNGImageDecoder.sendPixels(PNGImageDecoder.java:531)
    	at sun.awt.image.PNGImageDecoder.produceImage(PNGImageDecoder.java:452)
    	at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:246)
    	at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172)
    	at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)
    Exception in thread "Image Fetcher 0" Exception in thread "Image Fetcher 1" java.lang.OutOfMemoryError: Java heap space
    	at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:41)
    	at java.awt.image.Raster.createPackedRaster(Raster.java:458)
    	at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1015)
    	at sun.awt.image.ImageRepresentation.createBufferedImage(ImageRepresentation.java:230)
    	at sun.awt.image.ImageRepresentation.setPixels(ImageRepresentation.java:528)
    	at sun.awt.image.ImageDecoder.setPixels(ImageDecoder.java:120)
    	at sun.awt.image.PNGImageDecoder.sendPixels(PNGImageDecoder.java:531)
    	at sun.awt.image.PNGImageDecoder.produceImage(PNGImageDecoder.java:452)
    	at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:246)
    	at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172)
    	at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)
    java.lang.OutOfMemoryError: Java heap space
    	at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:41)
    	at java.awt.image.Raster.createPackedRaster(Raster.java:458)
    	at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1015)
    	at sun.awt.image.ImageRepresentation.createBufferedImage(ImageRepresentation.java:230)
    	at sun.awt.image.ImageRepresentation.setPixels(ImageRepresentation.java:528)
    	at sun.awt.image.ImageDecoder.setPixels(ImageDecoder.java:120)
    	at sun.awt.image.PNGImageDecoder.sendPixels(PNGImageDecoder.java:531)
    	at sun.awt.image.PNGImageDecoder.produceImage(PNGImageDecoder.java:452)
    	at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:246)
    	at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172)
    	at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)
    Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space
    Exception in thread "Image Fetcher 1" java.lang.OutOfMemoryError: Java heap space
    Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space
    Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space
    Exception in thread "Image Fetcher 1" java.lang.OutOfMemoryError: Java heap space
    Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space
    Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space
    Exception in thread "Image Fetcher 1" java.lang.OutOfMemoryError: Java heap space
    Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space

    it says something about images, i thought that the reason might be the amount of images i put in the code to load, i removed some of them, and the program runs, what is the problem behind this? i searched some on the web, and i ended up with the VisualVM, profiling something, i know where to open that program, but i dont know how to use it to asses my java heap space problem any help please..


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: VisualVM: Monitoring the Images instances being loaded that causes Java Heap Spac

    java.lang.OutOfMemoryError: Java heap space

    first line of the error man. out of memory

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: VisualVM: Monitoring the Images instances being loaded that causes Java Heap Spac

    There is not much to profile if your program is just running out of memory due to the number and size of the images you load - which looks to be the case here, and a profiler will tell you just that. Increase the heap size by using the -Xmx VM argument to an appropriate size, or load the images lazily (I would doubt you need every single one of those images at any one time). If the exception is spurious and unpredictable, a profiler will help to track down leaks due to references and caching

  4. The Following User Says Thank You to copeg For This Useful Post:

    chronoz13 (August 16th, 2012)

  5. #4
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: VisualVM: Monitoring the Images instances being loaded that causes Java Heap Spac

    Increase the heap size by using the -Xmx VM argument to an appropriate size
    thank you for pointing me at the right direction again, thats what i was thinking, adjusting the heap size, but i decided to ask first, and by the way, is it because every image is loaded "STATICALLY" means that as long as the program is running, the class is loaded, all the image references is "JUST THERE"? im about to try this but.. would i minimize the outcome, by just creating instances of that class, call an instance method , load the image, and just return the only images i need?

  6. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: VisualVM: Monitoring the Images instances being loaded that causes Java Heap Spac

    Quote Originally Posted by chronoz13 View Post
    thank you for pointing me at the right direction again, thats what i was thinking, adjusting the heap size, but i decided to ask first, and by the way, is it because every image is loaded "STATICALLY" means that as long as the program is running, the class is loaded, all the image references is "JUST THERE"? im about to try this but.. would i minimize the outcome, by just creating instances of that class, call an instance method , load the image, and just return the only images i need?
    How you do it is up to you. If you do not need all the images at a single time, then you can only load them when needed - this will reduce the memory footprint as well as allow the 'loaded but not needed anymore' references to be garbage collected.

Similar Threads

  1. Java Heap Space
    By aussiemcgr in forum Java Theory & Questions
    Replies: 4
    Last Post: September 8th, 2010, 05:05 PM
  2. Replies: 15
    Last Post: February 28th, 2010, 10:30 PM
  3. Java heap space error
    By Loki in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 27th, 2010, 10:47 PM
  4. Out of memory - Java heap space
    By fraxx in forum Java Theory & Questions
    Replies: 4
    Last Post: November 24th, 2009, 05:26 AM
  5. OutOfMemoryError (Java heap space)
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 21st, 2009, 11:56 AM