I met a OOM-issue of FAN native ads with the latest version 4.28.0.I want the FAN native ads refresh every 10 seconds,so I create a new instance of NativeAd and load ad every 10s.Implemented as the official docs says. I reproduced this issue in official demo too.To reproduce easily,I changed the interval time from 10s to 2s. here is the sample code of my test:
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);
}
It is running well at the beginning, but about an hour later,crashed.here is the crash log:
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)
Can anyone help me?
this issue seems be fixed in the latest version v4.28.1.