I am writing an diary App with iCloud+Core data resolution.While my developing. I found that the iCloud Storage only increase even I try to delete my diary in my app .I use the one to many. one is the Diary(title,content,...) and the many is the Photos. At first, I create some diarys with some photo, then i delete some photos. but the iCloud storage just increase,not decrease... After knowing this proble,i try to turn off the iCloud,switch the context to local Core Date Store,I found it doesn't has the proble i describe above. I don't know why will this happen. Please help me. thank you.
Here is the output of SQL of Core Data when I delete the photo in iCloud Store.
2015-12-23 09:10:27.991 LPDiary[749:215074] CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZCONTENT, t0.ZDIARYID, t0.ZLOCATION, t0.ZNOTEPAPERNAME, t0.ZRESERVEBINARYDATA1, t0.ZRESERVEBINARYDATA2, t0.ZRESERVEDATE1, t0.ZRESERVEDATE2, t0.ZRESERVESTR1, t0.ZRESERVESTR2, t0.ZTYPE, t0.ZWEATHER, t0.ZWRITEDATE FROM ZLCLDIARY t0 WHERE t0.ZDIARYID = ? ORDER BY t0.ZWRITEDATE DESC
2015-12-23 09:10:27.992 LPDiary[749:215074] CoreData: annotation: sql connection fetch time: 0.0009s
2015-12-23 09:10:27.992 LPDiary[749:215074] CoreData: annotation: total fetch execution time: 0.0013s for 1 rows.
2015-12-23 09:10:27.995 LPDiary[749:215074] CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZIMAGEDATA, t0.ZORDER, t0.ZRESERVESTR1, t0.ZOWNER, t0.Z1PHOTOS FROM ZLCLPHOTO t0 WHERE t0.Z_PK IN (?)
2015-12-23 09:10:27.997 LPDiary[749:215074] CoreData: annotation: sql connection fetch time: 0.0017s
2015-12-23 09:10:27.997 LPDiary[749:215074] CoreData: annotation: total fetch execution time: 0.0026s for 1 rows.
2015-12-23 09:10:28.000 LPDiary[749:215074] CoreData: sql: BEGIN EXCLUSIVE
2015-12-23 09:10:28.000 LPDiary[749:215074] CoreData: sql: DELETE FROM ZLCLPHOTO WHERE Z_PK = ? AND Z_OPT = ?
2015-12-23 09:10:28.007 LPDiary[749:215074] CoreData: sql: UPDATE ZLCLDIARY SET Z_OPT = ? WHERE Z_PK = ? AND Z_OPT = ?
2015-12-23 09:10:28.008 LPDiary[749:215074] CoreData: sql: UPDATE Y_UBMETA set YPEERID="mobile~5C6B0588-0876-42C4-88CA-2FC85745ED66", YTRANSACTIONNUMBER=30 WHERE YPEERID="mobile~5C6B0588-0876-42C4-88CA-2FC85745ED66"
2015-12-23 09:10:28.046 LPDiary[749:215074] CoreData: sql: COMMIT
2015-12-23 09:10:28.061 LPDiary[749:215074] CoreData: sql: select YPEERID, YTRANSACTIONNUMBER, Y_PK from Y_UBMETA
Core Data without iCloud works as you might expect. When you add data, the persistent store gets larger, and when you delete data it gets smaller.
Core Data with iCloud works by creating a baseline data store and then adding transaction logs that modify the baseline. When you add data, there's a new transaction that says to add the data. When you delete data, there's a new transaction that says to delete the data. But the transaction doesn't actually delete the data-- it just says that the data should be deleted, so that when transactions are replayed, the data is removed.
At some point Core Data is supposed to condense all of the transactions into a new baseline. Deleted data would be removed at that point. However Apple doesn't document when this happens, and I'm not sure that it ever does happen.
That's why you see different results depending on whether iCloud is enabled for Core Data.