将ContentValues重用于表操作的几个insert()是否安全?

时间:2014-11-09 17:51:04

标签: android android-sqlite

在将对象列表写入数据库时​​重用相同的ContentValues实例是否安全?

ContentValues row = new ContentValues();
for (Businessman businessman : aLotOfBusinessmen) {
    row.put(BusinessmanEntry.COLUMN_ADDRESS, businessman.getAddress());
    row.put(BusinessmanEntry.COLUMN_CASH, businessman.getCash());
    db.insert(BusinessmanEntry.TABLE_NAME, null, row);
}

1 个答案:

答案 0 :(得分:2)

它不仅安全,而且更好,因为您将避免与为循环体的每次执行创建ContentValues的不同实例相关联的内存分配(以及后续GC)。 / p>