Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 668637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:03:45+00:00 2026-05-14T00:03:45+00:00

I am currently trying to create an Android application that loops Audio from the

  • 0

I am currently trying to create an Android application that loops Audio from the mic to the earpiece, I can do that perfectly but when I do it over and over again in my application I eventually get an Out Of Memory Error.


Here is the code I use to create the Audio Loop:

static final int bufferSize = 200000;
    final short[] buffer = new short[bufferSize];
    short[] readBuffer = new short[bufferSize];

    public void run() {  
      isRecording = true;
      android.os.Process.setThreadPriority
      (android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);

      int buffersize = AudioRecord.getMinBufferSize(11025,
      AudioFormat.CHANNEL_CONFIGURATION_MONO,
      AudioFormat.ENCODING_PCM_16BIT);


                     arec = new AudioRecord(MediaRecorder.AudioSource.MIC,
                                     11025,
                                     AudioFormat.CHANNEL_CONFIGURATION_MONO,
                                     MediaRecorder.AudioEncoder.AMR_NB,
                                     buffersize);
                     atrack = new AudioTrack(AudioManager.STREAM_VOICE_CALL,
                                     11025,
                                     AudioFormat.CHANNEL_CONFIGURATION_MONO,
                                     MediaRecorder.AudioEncoder.AMR_NB,
                                     buffersize,
                                     AudioTrack.MODE_STREAM);

                     Log.d("AUDIO", "sample rate = : " + arec.getSampleRate());

                     atrack.setPlaybackRate(11025);

                     byte[] buffer = new byte[buffersize];
                     arec.startRecording();
                     atrack.play();

                     while(isRecording) {
                             arec.read(buffer, 0, buffersize);
                             atrack.write(buffer, 0, buffer.length);
                     }  

    }

And here is the error I get:

ERROR/AndroidRuntime(3442): Uncaught handler: thread main exiting due to uncaught exception
ERROR/AndroidRuntime(3442): java.lang.OutOfMemoryError
ERROR/AndroidRuntime(3442):     at com.phone.engine.CallAudio$Record.<init>(CallAudio.java:114)
ERROR/AndroidRuntime(3442):     at com.phone.engine.CallAudio.onCreate(CallAudio.java:42)
ERROR/AndroidRuntime(3442):     at android.app.ActivityThread.handleCreateService(ActivityThread.java:2465)
ERROR/AndroidRuntime(3442):     at android.app.ActivityThread.access$2800(ActivityThread.java:112)
ERROR/AndroidRuntime(3442):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1744)
ERROR/AndroidRuntime(3442):     at android.os.Handler.dispatchMessage(Handler.java:99)
ERROR/AndroidRuntime(3442):     at android.os.Looper.loop(Looper.java:123)
ERROR/AndroidRuntime(3442):     at android.app.ActivityThread.main(ActivityThread.java:3948)
ERROR/AndroidRuntime(3442):     at java.lang.reflect.Method.invokeNative(Native Method)
ERROR/AndroidRuntime(3442):     at java.lang.reflect.Method.invoke(Method.java:521)
ERROR/AndroidRuntime(3442):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
ERROR/AndroidRuntime(3442):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
ERROR/AndroidRuntime(3442):     at dalvik.system.NativeStart.main(Native Method)

So the Error specifically focuses on this line in the code

short[] readBuffer = new short[bufferSize];

And it happens after I try to do the Loop several times, so say I start the application and after 10 times starting the loop I get the error.

So I think the buffer is simply becomiing full or something?? Is that correct? If so how would I keep clearing out the buffer?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:03:45+00:00Added an answer on May 14, 2026 at 12:03 am

    According to the API docs, you must stop the recording and release the instance. Otherwise, it’ll hog system resources and you’ll eventually run out. So add the necessary cleanup code and it should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.