Le 22 mars 07 à 16:11, Yen-Ju Chen a écrit :

On 3/22/07, Quentin Mathé <[EMAIL PROTECTED]> wrote:

From UKRunner.m latest version:

     /* We use local variable so that the testObject will not be
messed up.

What do you mean by messed up?

 Because testObject is reused.
For example, two methods are tested, therefore, the loop will run twice.
 Then it will run like this:
 [testObject ini];
 [testObject performSelector: method1];
 [testObject release]; <- relased, may be dealloced.
 [testObject init]; <- memory leak.
 [testObject performSelector: method2];
 [testObject release]; <- released again.

Looks obvious now :-)

        And we have to distinguish class and instance
        because -init and -release apply to instance.

It's not clear to me why it's a problem since I was testing each time
whether the class object responds to -init or -initForTest (with
[object respondsToSelector: @selector(initForTest) for example)
before calling it… As a side note, the class could responds to -
initForTest if you added +initForTest method to your object
implementation code.

 Yes, for -init and initForTest, there is no farm
 and the check code can be removed if you want.
 At time time, I was more conservative about memory management.

ok

     /* FIXME: there is a memory leak because testObject comes
        here as allocated to tell whether it is class or instance.
        We can dealloc it here, but it is not really a good practice.
        Object is better to be pass as autoreleased. */

I don't see the memory leak.

 It is because testObject was -alloc before it comes to the method.
 We didn't release it here, and it is never released in the end.
 That is the leak I am taking about.

I completely forgot the main loop in fact. I just thought this method was called one time for each method when I wrote this reply.

  /* Test instance methods */
     testMethods = UKTestMethodNamesFromClass(testClass);
     [self runTests:testMethods onObject: [testClass alloc]]; <--
here is the allocation

in -runTests:onObject:

             if ([testObject respondsToSelector: @selector
(releaseForTest)])
                        {
[testObject releaseForTest]; <-- here is the deallocation
(possibility 1)
                        }
else if ([testObject respondsToSelector: @selector(release)])
                        {
[testObject release]; <-- here is the deallocation (possibility 2)
                        }

 Your analyze is right for the first loop.
 But if loop run more than once, the same testObject will be
dealloced more than once.
That is why I use a local variable and alloc local instance for the loop
 while keep testObject untouched.

 To sum up:
 1. -init and -initForTest can apply to instance and class. The code
is too conservative.
     (PS. class method is like function call. I don't see the use of
+init or +initForTest.
       It should be done in +instanize, I guess.).

Do you mean +initialize? Well I think we could optionally support +initializeForTest (not sure that's very useful).

 2. Better not to reused testObject because it will be released
multipl times in the loop.

By the way it's definitely better to keep the code as you modified it until we have time to rethink it just to be nicer (no difference between class object and instance testing… well if possible).

Cheers,
Quentin.


_______________________________________________
Etoile-dev mailing list
[email protected]
https://mail.gna.org/listinfo/etoile-dev

Reply via email to