editfmah / sharkorm

Shark ORM for iOS/macOS/tvOS/watchOS
http://sharkorm.com
Other
247 stars 39 forks source link

CFRelease & common_removeAllObjects #103

Open stefanosisto opened 6 years ago

stefanosisto commented 6 years ago

Hello. I have 2.1.0 version of pod and I'm having a lot of crash reported with Fabric. Iphone 5 and 5C, not other iphone. I've send to you the crash reports in your email. I'm waiting for a solution. Thanks

stefanosisto commented 6 years ago

these are the crashes on 5 & 5c 10.3.3

schermata 2018-07-31 alle 17 18 25 schermata 2018-07-31 alle 17 20 45
editfmah commented 6 years ago

The object is being free'd. You need to hold onto the objects for their lifecycle.

stefanosisto commented 6 years ago

Why it happens only on 10.3.3 and only on iPhone 5 & 5C? What I have to do to avoid this?

editfmah commented 6 years ago

Because every device has different capabilities and memory pressures. So, iOS on smaller devices may wish to cleanup more often than say an iPad Pro 12. They change these things from time to time with certain iOS builds, and SDK versions.

To stop it happening make sure you hold onto the results in a strong way, by assignment to a property or an IVar.

editfmah commented 6 years ago

Obviously it might not be that, as it's fairly hard to see what it could be without a full overview of the situation. But the fact that messages are being sent to a deallocated instance leads me to that juncture.

stefanosisto commented 6 years ago

Can you give me an example? Now I Have a json with 700 tuples. I'm reading it and creating NSNumber, NSString etc.... Then I'm assigning it to my istance.

So I'm doing:

Transaction ({ var obj = ObjectDB(); obj.a = 1; obj.b = 2; obj.c = 3; obj.commit() }). { print("fail") }

And after this insertOrUpdate, I'm just reading with queries, never more update.. So I really don't know where I'm releasing the var that I'm using.

stefanosisto commented 6 years ago

I have an addon for this. I've found an iphone 5c so I'm testing on it. ViewController in which i call SharkORMManager.load(parameters). In this method I have these lines of code: let result = SharkORM.rawQuery(query).rawResults let returnArray = []() for r in rawResult { let myResult = Class() myResult.a =r[key] as! Int myResult.b = r[key] as! Int etc... returnArray.append(myResult) } completion(returnArray).

In the ViewController i have the completion and I'm doing: { self.result = returnArray tableView.reloadData() } And after reloadData... it crashes in the malloc!!!! (olnly on 5, 5c, ipad4) (It happens with a rawResult with >200 rows) self.result is correctly assigned, it has the values before reloadData(). But I think it's something releasing memory by Shark before all the value are stored in my array... something like that. Btw it crashes exactly after .reloadData() in the malloc() of SRK. I was thinking about memory issue passing in the completion, so I've tried also to move (just for testing) the code in the viewController. So i'm calling rawResult in the viewController and cicling on it. But it crashes at same point after tableView.reloadData() Any suggestion?

stefanosisto commented 6 years ago

@editfmah Another update... It crashes also on iPhone 5 simulator on my macbook. So I Think is something related to iOS 10, not a memory issue with the phone...

schermata 2018-08-01 alle 18 35 41
stefanosisto commented 6 years ago

No solution for this? It crashes every time if I use an iPhone 5 simulator (or real device iPhone 5) with iOS 10.3 (or less). No crash in iPhone 5s simulator (or real device iPhone 5s) with iOS 10.3 @editfmah

editfmah commented 6 years ago

Hi @stefanosisto,

I have just tried one of our products on an iPhone 5, iOS 10.0.2 and I could not replicate your issue. That said, we are not driving much from table views so it is not a particularly accurate test.

Could you enable Zombie objects in the schema and see if you hit any zombie objects before the point you normally get this crash.

Thanks

stefanosisto commented 6 years ago

If you have skype, we can talk on Skype and I can share my screen. But only if you have 5 minute. So I can show you better what ( and when ) happens

editfmah commented 6 years ago

Sure thing, I will be available in around an hour if that's okay. My skype handle (*installs skype), is/was adrian_herridge

stefanosisto commented 6 years ago

Ok, i will be online :)