[V4CC] about autorelease of Vcursor
Ruslan Zasukhin
ruslan_zasukhin at valentina-db.com
Tue Aug 24 12:17:49 CDT 2010
On 8/17/10 6:08 PM, "Erne" <ernestogiannotta at tiscalinet.it> wrote:
Hi Erne,
>>> encountered some issues with this build:
>>>
>>> first why did you remove the VCursor contructor (initWithDB)?
>>
>> Because such constructor was only in V4RB some time ago,
>> And it was "copied" into V4CC.
>>
>> All other Valentina ADKs do not have it.
>> So we just have to unify API.
>>
>>
>> ---------------
>>> This was a lot useful when trying to query several cursor in a row with a
>>> readwrite lock
>>
>> This is not clear to me. Example ?
>>
>>> I mean the standard DB SqlQuery method returns an autoreleased object that
>>> will keep the lock alive for the entire main loop cycle.
>>
>>> If you don't want we alloc init our cursors we at least need a destructor or
>>> unlock method for the cursor.
>>
>> Again - explain please.
>>
>> Just have point that since V4CC have start to use autorelease.
>> Developers should start to use NSAutoReleasePool to control life of cursor.
>>
>
> Well, for the [mDB sqlSelect] method it's correct to return an autoreleased
> VCursor object
> and that's OK for most tasks.
>
> But imagine this simple scenario:
> I got a method that queries the db like this to populate list a
>
> VCursor *c1 = [mDB sqlSelect:sqlString
> cursorLocation:EVCursorLocation_kServerSide
> lockType:EVLockType_kNoLocks
> direction:EVCursorDirection_kRandom];
>
> now in the same method I call another method that eventually queries the same
> db to populate list b
>
> VCursor *c2 = [mDB sqlSelect:anotherSqlString
> cursorLocation:EVCursorLocation_kServerSide
> lockType:EVLockType_kNoLocks
> direction:EVCursorDirection_kRandom];
>
> If some record is already locked by the first query I get a Lock error by
> Valentina engine
> and there's no way for me to free that lock until I exit the first method and
> the autorelease pool will destroy c1 cursor
> because if I call [c1 release] before calling the second method
> then the autorelease pool will crash attempting to release the same object
> twice.
>
> This will be most crucial in a multiuser environment where locks are most
> important
>
> So it would either be useful a [c freeLocks] method
> or a contructor like we had before that will return a not autoreleased object
> so that we own our cursor and will be responsible for releasing it.
No no Erne,
Once again. Official way from Apple now is
Use NSAutoReleasePool !!
Foo()
{
{
NSAutoreleasePool *innerPool = [[NSAutoreleasePool alloc] init];
VCursor *c1 = [mDB sqlSelect:sqlString
cursorLocation:EVCursorLocation_kServerSide
lockType:EVLockType_kNoLocks
direction:EVCursorDirection_kRandom];
[ innerPool release]; <<<<< this will really destroy c1 !
}
}
In the NET they also should use special construction to force true object
death:
using( Vcursor curs1 = db.SqlSelect(...) )
{
}
--
Best regards,
Ruslan Zasukhin
VP Engineering and New Technology
Paradigma Software, Inc
Valentina - Joining Worlds of Information
http://www.paradigmasoft.com
[I feel the need: the need for speed]
More information about the Valentina
mailing list