FAN Native ads refresh:java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again
FAN Native ads refresh:java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again
我遇到了最新版本 4.28 的 FAN 原生广告的 OOM 问题。0.I 希望 FAN 原生广告每 10 秒刷新一次,所以我创建了一个新的 NativeAd 实例并每隔 10s.Implemented 正如官方文档所说。 我在官方demo中重现了这个问题too.To重现很容易,我把间隔时间从10s改成了2s。这里是我测试的示例代码:
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.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)
谁能帮帮我?
此问题似乎已在最新版本 v4.28.1 中修复。
我遇到了最新版本 4.28 的 FAN 原生广告的 OOM 问题。0.I 希望 FAN 原生广告每 10 秒刷新一次,所以我创建了一个新的 NativeAd 实例并每隔 10s.Implemented 正如官方文档所说。 我在官方demo中重现了这个问题too.To重现很容易,我把间隔时间从10s改成了2s。这里是我测试的示例代码:
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.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)
谁能帮帮我?
此问题似乎已在最新版本 v4.28.1 中修复。