Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Memory leaks with instance created by rb_class_wrap_new() #59

Closed
Watson1978 opened this issue Dec 5, 2016 · 0 comments
Closed
Labels

Comments

@Watson1978
Copy link
Member

We allocate instance using class_createInstance() on Darwin.
We have to call - [obj autorelease] where create an instance to avoid memory leak on Darwin, like

[[[Foo alloc] init] autolease];

However, class_createInstance() is

[Foo alloc]
Watson1978 added a commit that referenced this issue Dec 5, 2016
Watson1978 added a commit that referenced this issue Dec 5, 2016
`class_createInstance()` fills following structure fields properly.

```
struct objc_class {
    Class isa  OBJC_ISA_AVAILABILITY;

#if !__OBJC2__
    Class super_class                                        OBJC2_UNAVAILABLE;
    const char *name                                         OBJC2_UNAVAILABLE;
    long version                                             OBJC2_UNAVAILABLE;
    long info                                                OBJC2_UNAVAILABLE;
    long instance_size                                       OBJC2_UNAVAILABLE;
    struct objc_ivar_list *ivars                             OBJC2_UNAVAILABLE;
    struct objc_method_list **methodLists                    OBJC2_UNAVAILABLE;
    struct objc_cache *cache                                 OBJC2_UNAVAILABLE;
    struct objc_protocol_list *protocols                     OBJC2_UNAVAILABLE;
#endif

} OBJC2_UNAVAILABLE;
```

Our `klass` in `struct rb_class_ptr` covers `isa` of `struct objc_class`.
If store a value in `klass`, it will break `isa`.
And then we cannot call Objective-C method on its instance.
@Watson1978 Watson1978 added the Leak label Dec 6, 2016
Watson1978 added a commit that referenced this issue Dec 15, 2016
When container and child have a relationship,
we have to retain a child object.

If not, a child object will be released.
Watson1978 added a commit that referenced this issue Dec 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant