2 Replies Latest reply: Feb 1, 2012 12:08 AM by 914494 RSS

    targetdataline.stop() causes memory alloc error

    914494
      Hi,

      Im trying to run a Thread that records Audio when I press a button. I have no problem starting the thread, but I cannot seem to stop it without receiving memory alloc errors. Im try to stop is using targetdataline.stop followed by targetdataline.close .

      I am running Java SE 6 version 1.6.0_29-b11-402, on Mac OS X (I am also using Netbeans IDE 7.1)


      java(20704,0x1100ec000) malloc: *** error for object 0x2f6a6f72706c2e68: pointer being freed was not allocated
      *** set a breakpoint in malloc_error_break to debug
      Java Result: 134



      public AudioThread(String fileName) throws LineUnavailableException {

      soundFile = new File(fileName+ ".wav");
      audioFormat = new AudioFormat(8000.0F, 16, 1, true, false);
      dataLineInfo = new DataLine.Info(TargetDataLine.class,audioFormat);
      targetDataLine = (TargetDataLine) AudioSystem.getLine(dataLineInfo);
      audioInputStream = new AudioInputStream(targetDataLine);
      targetDataLine.open(audioFormat);

      }

      @Override
      public void run(){
      try {
      AudioSystem.write(audioInputStream, Type.WAVE, soundFile);
      }

      catch (IOException ex) {
      Logger.getLogger(AudioThread.class.getName()).log(Level.SEVERE, null, ex);
      }

      }
      public void startThread() throws LineUnavailableException {
      targetDataLine.start();
      super.start();
      }
      public void stopThread() throws IOException{
      targetDataLine.stop();
      targetDataLine.close();

      }

      Thanks,
      Lucas
        • 1. Re: targetdataline.stop() causes memory alloc error
          EJP
          Does it happen after the stop() or after the close()? I suspect you should have the thread do its own close() and just call stop() in the controlling thread.
          • 2. Re: targetdataline.stop() causes memory alloc error
            914494
            It seems to happen after the close() .

            I tried moving the targetdataline.close() at the end of run() function (after the AudioSystem.write() ), but no such luck.

            ...

            public void run(){
            try {
            AudioSystem.write(audioInputStream, Type.WAVE, soundFile);
            }

            catch (IOException ex) {
            Logger.getLogger(AudioThread.class.getName()).log(Level.SEVERE, null, ex);
            }
            targetDataLine.close();
            }


            public void stopThread() throws IOException{
            targetDataLine.stop();

            }
            ...