Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.OutOfMemoryError when loading a large DNS Block List. #24

Open
jpolstre opened this issue Aug 15, 2024 · 1 comment
Open

java.lang.OutOfMemoryError when loading a large DNS Block List. #24

jpolstre opened this issue Aug 15, 2024 · 1 comment
Assignees
Labels

Comments

@jpolstre
Copy link

jpolstre commented Aug 15, 2024

I'm trying to use this list: https://raw.githubusercontent.com/hagezi/dns-blocklists/main/domains/pro.txt Modify AdBlockerRepositoryImpl to avoid comments:

....
final response = await _getDataWithCache(_url);
 final results = <Host>[];
 for (final e in LineSplitter.split(response)) { 
    if (!e.startsWith('#')) { 
     final host = Host(authority: e);
     results.add(host);
    } 
 } 
return results;

The list loads, but when I try to use it to block ads, the app closes and I receive:

W/flutter.example( 6170): Throwing OutOfMemoryError "Failed to allocate a 16 byte allocation with 7704 free bytes and 7632B until OOM, target footprint 201326592, growth limit 201326592; giving up on allocation because <1% of heap free after GC." (VmSize 18446416 kB) E/AndroidRuntime( 6170): FATAL EXCEPTION: main E/AndroidRuntime( 6170): Process: com.islamdidarmd.example.adblockerwebview.flutter.example, PID: 6170 E/AndroidRuntime( 6170): java.lang .OutOfMemoryError: Failed to allocate a 16 byte allocation with 7704 free bytes and 7632B until OOM, target footprint 201326592, growth limit 201326592; giving up on allocation because <1% of heap free after GC.
E/AndroidRuntime( 6170): at io.flutter.plugin.common.StandardMessageCodec.readValueOfType(StandardMessageCodec.java:381) E/AndroidRuntime( 6170): at io.flutter.plugin.common.StandardMessageCodec.readValue(StandardMessageCodec.java: 340) E/AndroidRuntime( 6170): at io.flutter.plugin.common.StandardMessageCodec.readValueOfType(StandardMessageCodec.java:434) E/AndroidRuntime( 6170): at io.flutter.plugin.common.StandardMessageCodec.readValue(StandardMessageCodec.java:340) E/AndroidRuntime( 6170): at io.flutter.plugin.common.StandardMessageCodec.readValueOfType(StandardMessageCodec.java:434) E/AndroidRuntime( 6170) : at io.flutter.plugin.common.StandardMessageCodec.readValue(StandardMessageCodec.java:340) E/AndroidRuntime( 6170): at io.flutter.plugin.common.StandardMessageCodec.readValueOfType(StandardMessageCodec.java:424) E/AndroidRuntime( 6170): at io.flutter.plugin.common.StandardMessageCodec.readValue(StandardMessageCodec.java:340)
E/AndroidRuntime( 6170): at io.flutter.plugin.common.StandardMessageCodec.readValueOfType(StandardMessageCodec.java:434)

I also tried adding AndroidManifest.xml :

android:hardwareAccelerated="true"
android:largeHeap="true",

but I still get the same error, it seems flutter_inappwebview, _inAppWebViewOptions?.crossPlatform.contentBlockers, is not optimized to handle large lists.

@islamdidarmd islamdidarmd self-assigned this Aug 15, 2024
@islamdidarmd
Copy link
Owner

Hi thank you for trying this out raising this issue. I will investigate more about this.

If flutter_inappwebview is indeed the one what is causing the issue, I might have to use native webview for this. Implementing own webview will take time. Meanwhile, can you provide a minimum reproducible sample?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants