Skip to content

When syncing large note: OutOfMemoryError via generateNoteExcerpt in NoteUtil #1901

Open
@eltos

Description

@eltos

Please use GitHub reactions 👍 to show that you are affected by the same issue. Please don't comment if you have no relevant information to add!

Describe the bug

To Reproduce
Steps to reproduce the behavior:

  1. Have a large TXT file somewhere in your cloud
  2. In the nextcloud notes app, change the notes folder from "Notes" to root
  3. Open the android app
  4. Wait on main screen (notes list) for completion of sync
  5. See error

Unfortunately the error persists after several restarts of the app. The only way to solve it was to identify and rename the large TXT file blocking the sync.

Expected behavior

Sync all notes without errors. If syncing all at once is too memory intensive, sync in batches (and clean up memory in between).

Also I would not expect the app to parse the full markdown just to create a preview excerpt with the first 200 char. Instead, parsing the first few non-empty lines or 1000 chars only could save a lot of memory. If really required, more lines/chars can be parsed iteratively.
And for a TXT file, there is no point in parsing markdown at all.

Screenshots

Smartphone (please complete the following information):

  • Nextcloud Notes-Version (android app): 4.1.0 (40010090)
  • F-Droid or Play Store: play
  • Android-Version: 13 (API 33)
  • Device: SM-G781B

Server

  • Nextcloud version: 26.0.5
  • Nextcloud Notes version (server app): 4.8.1

Stacktrace

java.lang.OutOfMemoryError: Failed to allocate a 32 byte allocation with 125776 free bytes and 122KB until OOM, target footprint 268435456, growth limit 268435456; giving up on allocation because <1% of heap free after GC.
	at org.commonmark.internal.InlineParserImpl.parseNewline(InlineParserImpl.java:301)
	at org.commonmark.internal.InlineParserImpl.parseInline(InlineParserImpl.java:196)
	at org.commonmark.internal.InlineParserImpl.parse(InlineParserImpl.java:153)
	at org.commonmark.internal.ParagraphParser.parseInlines(ParagraphParser.java:53)
	at org.commonmark.internal.DocumentParser.processInlines(DocumentParser.java:422)
	at org.commonmark.internal.DocumentParser.finalizeAndProcess(DocumentParser.java:480)
	at org.commonmark.internal.DocumentParser.parse(DocumentParser.java:117)
	at org.commonmark.parser.Parser.parse(Parser.java:69)
	at it.niedermann.android.markdown.MarkdownUtil.removeMarkdown(MarkdownUtil.java:521)
	at it.niedermann.owncloud.notes.shared.util.NoteUtil.generateNoteExcerpt(NoteUtil.java:67)
	at it.niedermann.owncloud.notes.persistence.NotesRepository.addNote(NotesRepository.java:441)
	at it.niedermann.owncloud.notes.persistence.NotesServerSyncTask.pullRemoteChanges(NotesServerSyncTask.java:239)
	at it.niedermann.owncloud.notes.persistence.NotesServerSyncTask.run(NotesServerSyncTask.java:96)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:463)
	at java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
	at java.lang.Thread.run(Thread.java:1012)

Sometimes also:

java.lang.OutOfMemoryError: OutOfMemoryError thrown while trying to throw an exception; no stack trace available

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions