Skip to content

Commit 5eefc65

Browse files
authored
Merge 7037127 into master-4.0
2 parents c10ce19 + 7037127 commit 5eefc65

28 files changed

Lines changed: 477 additions & 678 deletions

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@
3131
* Upgraded to Realm Core 3.0.0-rc3.
3232

3333

34+
## 3.7.1 (YYYY-MM-DD)
35+
36+
### Bug Fixes
37+
38+
* Fixed potential memory leaks of `LinkView` when calling bulk insertions APIs.
39+
40+
### Internal
41+
42+
* Replaced LinkView with Object Store's List.
43+
44+
3445
## 3.7.0 (2017-09-01)
3546

3647
### Deprecated

realm/realm-annotations-processor/src/main/java/io/realm/processor/RealmProxyClassGenerator.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class RealmProxyClassGenerator {
4949
"android.util.JsonToken",
5050
"io.realm.exceptions.RealmMigrationNeededException",
5151
"io.realm.internal.ColumnInfo",
52-
"io.realm.internal.LinkView",
52+
"io.realm.internal.OsList",
5353
"io.realm.internal.OsObject",
5454
"io.realm.internal.OsSchemaInfo",
5555
"io.realm.internal.OsObjectSchemaInfo",
@@ -519,8 +519,8 @@ private void emitRealmList(
519519
.beginControlFlow("if (" + fieldName + "RealmList != null)")
520520
.emitStatement("return " + fieldName + "RealmList")
521521
.nextControlFlow("else")
522-
.emitStatement("LinkView linkView = proxyState.getRow$realm().getLinkList(%s)", fieldIndexVariableReference(field))
523-
.emitStatement(fieldName + "RealmList = new RealmList<%s>(%s.class, linkView, proxyState.getRealm$realm())",
522+
.emitStatement("OsList osList = proxyState.getRow$realm().getLinkList(%s)", fieldIndexVariableReference(field))
523+
.emitStatement(fieldName + "RealmList = new RealmList<%s>(%s.class, osList, proxyState.getRealm$realm())",
524524
genericType, genericType)
525525
.emitStatement("return " + fieldName + "RealmList")
526526
.endControlFlow()
@@ -556,8 +556,8 @@ public void emit(JavaWriter writer) throws IOException {
556556
}
557557
});
558558
writer.emitStatement("proxyState.getRealm$realm().checkIfValid()")
559-
.emitStatement("LinkView links = proxyState.getRow$realm().getLinkList(%s)", fieldIndexVariableReference(field))
560-
.emitStatement("links.clear()")
559+
.emitStatement("OsList osList = proxyState.getRow$realm().getLinkList(%s)", fieldIndexVariableReference(field))
560+
.emitStatement("osList.removeAll()")
561561
.beginControlFlow("if (value == null)")
562562
.emitStatement("return")
563563
.endControlFlow()
@@ -568,7 +568,7 @@ public void emit(JavaWriter writer) throws IOException {
568568
.beginControlFlow("if (((RealmObjectProxy) linkedObject).realmGet$proxyState().getRealm$realm() != proxyState.getRealm$realm())")
569569
.emitStatement("throw new IllegalArgumentException(\"Each element of 'value' must belong to the same Realm.\")")
570570
.endControlFlow()
571-
.emitStatement("links.add(((RealmObjectProxy) linkedObject).realmGet$proxyState().getRow$realm().getIndex())")
571+
.emitStatement("osList.addRow(((RealmObjectProxy) linkedObject).realmGet$proxyState().getRow$realm().getIndex())")
572572
.endControlFlow()
573573
.endMethod();
574574
}
@@ -1010,13 +1010,13 @@ private void emitInsertMethod(JavaWriter writer) throws IOException {
10101010
.emitStatement("RealmList<%s> %sList = ((%s) object).%s()",
10111011
genericType, fieldName, interfaceName, getter)
10121012
.beginControlFlow("if (%sList != null)", fieldName)
1013-
.emitStatement("long %1$sNativeLinkViewPtr = Table.nativeGetLinkView(tableNativePtr, columnInfo.%1$sIndex, rowIndex)", fieldName)
1013+
.emitStatement("OsList %1$sOsList = new OsList(table.getUncheckedRow(rowIndex), columnInfo.%1$sIndex)", fieldName)
10141014
.beginControlFlow("for (%1$s %2$sItem : %2$sList)", genericType, fieldName)
10151015
.emitStatement("Long cacheItemIndex%1$s = cache.get(%1$sItem)", fieldName)
10161016
.beginControlFlow("if (cacheItemIndex%s == null)", fieldName)
10171017
.emitStatement("cacheItemIndex%1$s = %2$s.insert(realm, %1$sItem, cache)", fieldName, Utils.getProxyClassSimpleName(field))
10181018
.endControlFlow()
1019-
.emitStatement("LinkView.nativeAdd(%1$sNativeLinkViewPtr, cacheItemIndex%1$s)", fieldName)
1019+
.emitStatement("%1$sOsList.addRow(cacheItemIndex%1$s)", fieldName)
10201020
.endControlFlow()
10211021
.endControlFlow();
10221022

@@ -1090,13 +1090,13 @@ private void emitInsertListMethod(JavaWriter writer) throws IOException {
10901090
.emitStatement("RealmList<%s> %sList = ((%s) object).%s()",
10911091
genericType, fieldName, interfaceName, getter)
10921092
.beginControlFlow("if (%sList != null)", fieldName)
1093-
.emitStatement("long %1$sNativeLinkViewPtr = Table.nativeGetLinkView(tableNativePtr, columnInfo.%1$sIndex, rowIndex)", fieldName)
1093+
.emitStatement("OsList %1$sOsList = new OsList(table.getUncheckedRow(rowIndex), columnInfo.%1$sIndex)", fieldName)
10941094
.beginControlFlow("for (%1$s %2$sItem : %2$sList)", genericType, fieldName)
10951095
.emitStatement("Long cacheItemIndex%1$s = cache.get(%1$sItem)", fieldName)
10961096
.beginControlFlow("if (cacheItemIndex%s == null)", fieldName)
10971097
.emitStatement("cacheItemIndex%1$s = %2$s.insert(realm, %1$sItem, cache)", fieldName, Utils.getProxyClassSimpleName(field))
10981098
.endControlFlow()
1099-
.emitStatement("LinkView.nativeAdd(%1$sNativeLinkViewPtr, cacheItemIndex%1$s)", fieldName)
1099+
.emitStatement("%1$sOsList.addRow(cacheItemIndex%1$s)", fieldName)
11001100
.endControlFlow()
11011101
.endControlFlow();
11021102

@@ -1163,8 +1163,8 @@ private void emitInsertOrUpdateMethod(JavaWriter writer) throws IOException {
11631163
final String genericType = Utils.getGenericTypeQualifiedName(field);
11641164
writer
11651165
.emitEmptyLine()
1166-
.emitStatement("long %1$sNativeLinkViewPtr = Table.nativeGetLinkView(tableNativePtr, columnInfo.%1$sIndex, rowIndex)", fieldName)
1167-
.emitStatement("LinkView.nativeClear(%sNativeLinkViewPtr)", fieldName)
1166+
.emitStatement("OsList %1$sOsList = new OsList(table.getUncheckedRow(rowIndex), columnInfo.%1$sIndex)", fieldName)
1167+
.emitStatement("%1$sOsList.removeAll()", fieldName)
11681168
.emitStatement("RealmList<%s> %sList = ((%s) object).%s()",
11691169
genericType, fieldName, interfaceName, getter)
11701170
.beginControlFlow("if (%sList != null)", fieldName)
@@ -1173,7 +1173,7 @@ private void emitInsertOrUpdateMethod(JavaWriter writer) throws IOException {
11731173
.beginControlFlow("if (cacheItemIndex%s == null)", fieldName)
11741174
.emitStatement("cacheItemIndex%1$s = %2$s.insertOrUpdate(realm, %1$sItem, cache)", fieldName, Utils.getProxyClassSimpleName(field))
11751175
.endControlFlow()
1176-
.emitStatement("LinkView.nativeAdd(%1$sNativeLinkViewPtr, cacheItemIndex%1$s)", fieldName)
1176+
.emitStatement("%1$sOsList.addRow(cacheItemIndex%1$s)", fieldName)
11771177
.endControlFlow()
11781178
.endControlFlow()
11791179
.emitEmptyLine();
@@ -1247,8 +1247,8 @@ private void emitInsertOrUpdateListMethod(JavaWriter writer) throws IOException
12471247
final String genericType = Utils.getGenericTypeQualifiedName(field);
12481248
writer
12491249
.emitEmptyLine()
1250-
.emitStatement("long %1$sNativeLinkViewPtr = Table.nativeGetLinkView(tableNativePtr, columnInfo.%1$sIndex, rowIndex)", fieldName)
1251-
.emitStatement("LinkView.nativeClear(%sNativeLinkViewPtr)", fieldName)
1250+
.emitStatement("OsList %1$sOsList = new OsList(table.getUncheckedRow(rowIndex), columnInfo.%1$sIndex)", fieldName)
1251+
.emitStatement("%1$sOsList.removeAll()", fieldName)
12521252
.emitStatement("RealmList<%s> %sList = ((%s) object).%s()",
12531253
genericType, fieldName, interfaceName, getter)
12541254
.beginControlFlow("if (%sList != null)", fieldName)
@@ -1257,7 +1257,7 @@ private void emitInsertOrUpdateListMethod(JavaWriter writer) throws IOException
12571257
.beginControlFlow("if (cacheItemIndex%s == null)", fieldName)
12581258
.emitStatement("cacheItemIndex%1$s = %2$s.insertOrUpdate(realm, %1$sItem, cache)", fieldName, Utils.getProxyClassSimpleName(field))
12591259
.endControlFlow()
1260-
.emitStatement("LinkView.nativeAdd(%1$sNativeLinkViewPtr, cacheItemIndex%1$s)", fieldName)
1260+
.emitStatement("%1$sOsList.addRow(cacheItemIndex%1$s)", fieldName)
12611261
.endControlFlow()
12621262
.endControlFlow()
12631263
.emitEmptyLine();

realm/realm-annotations-processor/src/test/resources/io/realm/AllTypesRealmProxy.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import android.util.JsonToken;
88
import io.realm.exceptions.RealmMigrationNeededException;
99
import io.realm.internal.ColumnInfo;
10-
import io.realm.internal.LinkView;
10+
import io.realm.internal.OsList;
1111
import io.realm.internal.OsObject;
1212
import io.realm.internal.OsObjectSchemaInfo;
1313
import io.realm.internal.OsSchemaInfo;
@@ -361,8 +361,8 @@ protected final void copy(ColumnInfo rawSrc, ColumnInfo rawDst) {
361361
if (columnRealmListRealmList != null) {
362362
return columnRealmListRealmList;
363363
} else {
364-
LinkView linkView = proxyState.getRow$realm().getLinkList(columnInfo.columnRealmListIndex);
365-
columnRealmListRealmList = new RealmList<some.test.AllTypes>(some.test.AllTypes.class, linkView, proxyState.getRealm$realm());
364+
OsList osList = proxyState.getRow$realm().getLinkList(columnInfo.columnRealmListIndex);
365+
columnRealmListRealmList = new RealmList<some.test.AllTypes>(some.test.AllTypes.class, osList, proxyState.getRealm$realm());
366366
return columnRealmListRealmList;
367367
}
368368
}
@@ -391,8 +391,8 @@ protected final void copy(ColumnInfo rawSrc, ColumnInfo rawDst) {
391391
}
392392

393393
proxyState.getRealm$realm().checkIfValid();
394-
LinkView links = proxyState.getRow$realm().getLinkList(columnInfo.columnRealmListIndex);
395-
links.clear();
394+
OsList osList = proxyState.getRow$realm().getLinkList(columnInfo.columnRealmListIndex);
395+
osList.removeAll();
396396
if (value == null) {
397397
return;
398398
}
@@ -403,7 +403,7 @@ protected final void copy(ColumnInfo rawSrc, ColumnInfo rawDst) {
403403
if (((RealmObjectProxy) linkedObject).realmGet$proxyState().getRealm$realm() != proxyState.getRealm$realm()) {
404404
throw new IllegalArgumentException("Each element of 'value' must belong to the same Realm.");
405405
}
406-
links.add(((RealmObjectProxy) linkedObject).realmGet$proxyState().getRow$realm().getIndex());
406+
osList.addRow(((RealmObjectProxy) linkedObject).realmGet$proxyState().getRow$realm().getIndex());
407407
}
408408
}
409409

@@ -817,13 +817,13 @@ public static long insert(Realm realm, some.test.AllTypes object, Map<RealmModel
817817

818818
RealmList<some.test.AllTypes> columnRealmListList = ((AllTypesRealmProxyInterface) object).realmGet$columnRealmList();
819819
if (columnRealmListList != null) {
820-
long columnRealmListNativeLinkViewPtr = Table.nativeGetLinkView(tableNativePtr, columnInfo.columnRealmListIndex, rowIndex);
820+
OsList columnRealmListOsList = new OsList(table.getUncheckedRow(rowIndex), columnInfo.columnRealmListIndex);
821821
for (some.test.AllTypes columnRealmListItem : columnRealmListList) {
822822
Long cacheItemIndexcolumnRealmList = cache.get(columnRealmListItem);
823823
if (cacheItemIndexcolumnRealmList == null) {
824824
cacheItemIndexcolumnRealmList = AllTypesRealmProxy.insert(realm, columnRealmListItem, cache);
825825
}
826-
LinkView.nativeAdd(columnRealmListNativeLinkViewPtr, cacheItemIndexcolumnRealmList);
826+
columnRealmListOsList.addRow(cacheItemIndexcolumnRealmList);
827827
}
828828
}
829829
return rowIndex;
@@ -885,13 +885,13 @@ public static void insert(Realm realm, Iterator<? extends RealmModel> objects, M
885885

886886
RealmList<some.test.AllTypes> columnRealmListList = ((AllTypesRealmProxyInterface) object).realmGet$columnRealmList();
887887
if (columnRealmListList != null) {
888-
long columnRealmListNativeLinkViewPtr = Table.nativeGetLinkView(tableNativePtr, columnInfo.columnRealmListIndex, rowIndex);
888+
OsList columnRealmListOsList = new OsList(table.getUncheckedRow(rowIndex), columnInfo.columnRealmListIndex);
889889
for (some.test.AllTypes columnRealmListItem : columnRealmListList) {
890890
Long cacheItemIndexcolumnRealmList = cache.get(columnRealmListItem);
891891
if (cacheItemIndexcolumnRealmList == null) {
892892
cacheItemIndexcolumnRealmList = AllTypesRealmProxy.insert(realm, columnRealmListItem, cache);
893893
}
894-
LinkView.nativeAdd(columnRealmListNativeLinkViewPtr, cacheItemIndexcolumnRealmList);
894+
columnRealmListOsList.addRow(cacheItemIndexcolumnRealmList);
895895
}
896896
}
897897
}
@@ -950,16 +950,16 @@ public static long insertOrUpdate(Realm realm, some.test.AllTypes object, Map<Re
950950
Table.nativeNullifyLink(tableNativePtr, columnInfo.columnObjectIndex, rowIndex);
951951
}
952952

953-
long columnRealmListNativeLinkViewPtr = Table.nativeGetLinkView(tableNativePtr, columnInfo.columnRealmListIndex, rowIndex);
954-
LinkView.nativeClear(columnRealmListNativeLinkViewPtr);
953+
OsList columnRealmListOsList = new OsList(table.getUncheckedRow(rowIndex), columnInfo.columnRealmListIndex);
954+
columnRealmListOsList.removeAll();
955955
RealmList<some.test.AllTypes> columnRealmListList = ((AllTypesRealmProxyInterface) object).realmGet$columnRealmList();
956956
if (columnRealmListList != null) {
957957
for (some.test.AllTypes columnRealmListItem : columnRealmListList) {
958958
Long cacheItemIndexcolumnRealmList = cache.get(columnRealmListItem);
959959
if (cacheItemIndexcolumnRealmList == null) {
960960
cacheItemIndexcolumnRealmList = AllTypesRealmProxy.insertOrUpdate(realm, columnRealmListItem, cache);
961961
}
962-
LinkView.nativeAdd(columnRealmListNativeLinkViewPtr, cacheItemIndexcolumnRealmList);
962+
columnRealmListOsList.addRow(cacheItemIndexcolumnRealmList);
963963
}
964964
}
965965

@@ -1026,16 +1026,16 @@ public static void insertOrUpdate(Realm realm, Iterator<? extends RealmModel> ob
10261026
Table.nativeNullifyLink(tableNativePtr, columnInfo.columnObjectIndex, rowIndex);
10271027
}
10281028

1029-
long columnRealmListNativeLinkViewPtr = Table.nativeGetLinkView(tableNativePtr, columnInfo.columnRealmListIndex, rowIndex);
1030-
LinkView.nativeClear(columnRealmListNativeLinkViewPtr);
1029+
OsList columnRealmListOsList = new OsList(table.getUncheckedRow(rowIndex), columnInfo.columnRealmListIndex);
1030+
columnRealmListOsList.removeAll();
10311031
RealmList<some.test.AllTypes> columnRealmListList = ((AllTypesRealmProxyInterface) object).realmGet$columnRealmList();
10321032
if (columnRealmListList != null) {
10331033
for (some.test.AllTypes columnRealmListItem : columnRealmListList) {
10341034
Long cacheItemIndexcolumnRealmList = cache.get(columnRealmListItem);
10351035
if (cacheItemIndexcolumnRealmList == null) {
10361036
cacheItemIndexcolumnRealmList = AllTypesRealmProxy.insertOrUpdate(realm, columnRealmListItem, cache);
10371037
}
1038-
LinkView.nativeAdd(columnRealmListNativeLinkViewPtr, cacheItemIndexcolumnRealmList);
1038+
columnRealmListOsList.addRow(cacheItemIndexcolumnRealmList);
10391039
}
10401040
}
10411041

realm/realm-annotations-processor/src/test/resources/io/realm/BooleansRealmProxy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import android.util.JsonToken;
88
import io.realm.exceptions.RealmMigrationNeededException;
99
import io.realm.internal.ColumnInfo;
10-
import io.realm.internal.LinkView;
10+
import io.realm.internal.OsList;
1111
import io.realm.internal.OsObject;
1212
import io.realm.internal.OsObjectSchemaInfo;
1313
import io.realm.internal.OsSchemaInfo;

realm/realm-annotations-processor/src/test/resources/io/realm/NullTypesRealmProxy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import android.util.JsonToken;
88
import io.realm.exceptions.RealmMigrationNeededException;
99
import io.realm.internal.ColumnInfo;
10-
import io.realm.internal.LinkView;
10+
import io.realm.internal.OsList;
1111
import io.realm.internal.OsObject;
1212
import io.realm.internal.OsObjectSchemaInfo;
1313
import io.realm.internal.OsSchemaInfo;

realm/realm-annotations-processor/src/test/resources/io/realm/SimpleRealmProxy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import android.util.JsonToken;
88
import io.realm.exceptions.RealmMigrationNeededException;
99
import io.realm.internal.ColumnInfo;
10-
import io.realm.internal.LinkView;
10+
import io.realm.internal.OsList;
1111
import io.realm.internal.OsObject;
1212
import io.realm.internal.OsObjectSchemaInfo;
1313
import io.realm.internal.OsSchemaInfo;

realm/realm-library/src/androidTest/java/io/realm/RealmListTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import android.support.test.runner.AndroidJUnit4;
2020

21+
import org.hamcrest.CoreMatchers;
2122
import org.junit.After;
2223
import org.junit.Before;
2324
import org.junit.Rule;
@@ -46,6 +47,7 @@
4647
import static org.junit.Assert.assertEquals;
4748
import static org.junit.Assert.assertFalse;
4849
import static org.junit.Assert.assertNotNull;
50+
import static org.junit.Assert.assertThat;
4951
import static org.junit.Assert.assertTrue;
5052
import static org.junit.Assert.fail;
5153

@@ -781,7 +783,7 @@ public void removeAllFromRealm_outsideTransaction() {
781783
dogs.deleteAllFromRealm();
782784
fail("removeAllFromRealm should be called in a transaction.");
783785
} catch (IllegalStateException e) {
784-
assertEquals("Changing Realm data can only be done from inside a write transaction.", e.getMessage());
786+
assertThat(e.getMessage(), CoreMatchers.containsString("Must be in a write transaction "));
785787
}
786788
}
787789

@@ -1117,7 +1119,7 @@ public void createSnapshot_shouldUseTargetTable() {
11171119
realm.commitTransaction();
11181120
assertEquals(sizeBefore - 1, collection.size());
11191121

1120-
assertNotNull(collection.view);
1121-
assertEquals(collection.view.getTargetTable().getName(), snapshot.getTable().getName());
1122+
assertNotNull(collection.osList);
1123+
assertEquals(collection.osList.getTargetTable().getName(), snapshot.getTable().getName());
11221124
}
11231125
}

realm/realm-library/src/main/cpp/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ string(TOLOWER ${CMAKE_BUILD_TYPE} build_type_FOLDER)
3838
set(classes_PATH ${CMAKE_SOURCE_DIR}/../../../build/intermediates/classes/${REALM_FLAVOR}/${build_type_FOLDER}/)
3939
set(classes_LIST
4040
io.realm.internal.Table io.realm.internal.CheckedRow
41-
io.realm.internal.LinkView io.realm.internal.Util io.realm.internal.UncheckedRow
41+
io.realm.internal.Util io.realm.internal.UncheckedRow
4242
io.realm.internal.TableQuery io.realm.internal.SharedRealm io.realm.internal.TestUtil
4343
io.realm.log.LogLevel io.realm.log.RealmLog io.realm.internal.Property io.realm.internal.OsSchemaInfo
4444
io.realm.internal.OsObjectSchemaInfo io.realm.internal.Collection
4545
io.realm.internal.NativeObjectReference io.realm.internal.CollectionChangeSet
46-
io.realm.internal.OsObject io.realm.internal.OsRealmConfig
46+
io.realm.internal.OsObject io.realm.internal.OsRealmConfig io.realm.internal.OsList
4747
)
4848
# /./ is the workaround for the problem that AS cannot find the jni headers.
4949
# See https://github.com/googlesamples/android-ndk/issues/319

0 commit comments

Comments
 (0)