FAN原生广告刷新:java.lang.OutOfMemoryError:pthread_create(1040KB堆栈)失败:再试一次

时间:2018-03-30 07:00:19

标签: out-of-memory refresh facebook-audience-network native-ads

我遇到了一个OOM问题的FAN原生广告,最新版本为4.28.0。我希望FAN原生广告每10秒刷新一次,因此我创建了一个新的NativeAd实例并每10秒加载一次广告。作为官方实施docs说。 我也在官方演示中重现了这个问题。为了轻松复制,我将间隔时间从10秒更改为2秒。这里是我测试的示例代码:

private void showNativeAd() {
    nativeAd = new NativeAd(getContext(), mAdunit);
    nativeAd.setAdListener(new AdListener() {

        @Override
        public void onError(Ad ad, AdError error) {
            // Ad error callback
            Log.e(TAG,"failed-->" + error.getErrorMessage());
            //refresh after 2s
            requestDelay(2000);
        }

        @Override
        public void onAdLoaded(Ad ad) {
            Log.e(TAG,"loaded-->");
            // Add the Ad view into the ad container.
            //...

            //refresh after 2s
            requestDelay(2000);
        }

        @Override
        public void onAdClicked(Ad ad) {
            // Ad clicked callback
        }

        @Override
        public void onLoggingImpression(Ad ad) {
            // On logging impression callback
        }
    });

    // Request an ad
    nativeAd.loadAd();
  }

private void requestDelay(int millseconds){
   if (handler == null){
    handler = new Handler(Looper.getMainLooper());
   }
    handler.postDelayed(new Runnable() {
    @Override
    public void run() {
        showNativeAd();
    }
  },millseconds);
}

它在开始时运行良好,但是大约一个小时后,崩溃了。崩溃日志就是这样:

java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again
 at java.lang.Thread.nativeCreate(Native Method)
 at java.lang.Thread.start(Thread.java:1063)
 at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:920)
 at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1327)
 at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:590)
 at com.facebook.ads.internal.m.b$1.run(Unknown Source)
 at android.os.Handler.handleCallback(Handler.java:739)
 at android.os.Handler.dispatchMessage(Handler.java:95)
 at android.os.Looper.loop(Looper.java:145)
 at android.app.ActivityThread.main(ActivityThread.java:6145)
 at java.lang.reflect.Method.invoke(Native Method)
 at java.lang.reflect.Method.invoke(Method.java:372)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

此问题似乎已在最新版本v4.28.1中修复。