Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

android - Limit Realm results

How do I limit the amount of objects Realm returns? .findAll returns all rows matching the query and .findFirst returns only the first. But what about something like first 1000? .findAll may return so many rows that it consumes way too much memory.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The cool thing is that you don't need to worry about that with Realm. The result object returned from a query is lazily loading the objects and its fields when you access them. Your objects are never copied and thus only represented once in memory/disk.

The (current) implementation detail of this is that the RealmResults object returned from a query is just a list of references to the matching objects. Those references are tiny numbers which are stored compressed so they take up very little memory. So even with 100.000 matches it actually wouldn't take up much memory. And it would take up the same amount of memory for all kind of objects, whether they have one int field or hundreds of fields with strings or big binaries.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...