Skip to content
This repository has been archived by the owner on Jan 25, 2019. It is now read-only.

Spine - Leak Check #157

Open
vpetrenko90 opened this issue Feb 4, 2017 · 4 comments
Open

Spine - Leak Check #157

vpetrenko90 opened this issue Feb 4, 2017 · 4 comments

Comments

@vpetrenko90
Copy link

I have created a simple example using Spine:

  • Controller class:
import UIKit
import Spine

class ViewController: UIViewController {
    var spine: Spine!

    override func viewDidLoad() {
        super.viewDidLoad()

        setupSpine()
        getPosts()
    }

    func setupSpine() {

        spine = Spine(baseURL: URL(string: "http://test.com?access_token=test&page=1&per_page=15")!)
        
        spine.registerResource(Post.self)
        spine.registerResource(User.self)
    }
    
    func getPosts() {

        spine.findAll(Post.self).onSuccess { posts, meta, _ in
            for (_, postsResource) in posts.enumerated() {
                let post = postsResource as! Post

                print(post.user?.firstName ?? "", post.user?.lastName ?? "")
            }
        }.onFailure { error in
                print("Fetching failed: \(error)")
        }
    }
}
  • First Posts model:
import UIKit
import Spine

// Resource class
class Post: Resource {
    var user: User?
    var message: String?
    var dateAdd: String?
    var dateUpdate: String?

    override class var resourceType: ResourceType {
        return "posts"
    }
    
    override class var fields: [Field] {
        return fieldsFromDictionary([
            "user": ToOneRelationship(User.self),
            "message": Attribute(),
            "dateAdd": Attribute().serializeAs("date-add"),
            "dateUpdate": Attribute().serializeAs("date_update")
       ])
    }
}
  • Second Users model:
import UIKit
import Spine

class User: Resource {
    /// The ID of this resource.
    var email: String?
    var firstName: String?
    var lastName: String?
    var gender: NSNumber?
    var phone: String?
    var additionalPhone: String?
    var skype: String?
    var lastLogin: NSDate?
    var bday: NSDate?
    var role: String?
    var img: String?
    var isActive: NSNumber?
    
    override class var resourceType: ResourceType {
        return "users"
    }
    
    override class var fields: [Field] {
        return fieldsFromDictionary([
            "email": Attribute(),
            "firstName": Attribute().serializeAs("first-name"),
            "lastName": Attribute().serializeAs("last-name"),
            "gender": Attribute(),
            "phone": Attribute(),
            "additionalPhone": Attribute().serializeAs("additional-phone"),
            "skype": Attribute(),
            "lastLogin": Attribute().serializeAs("last-login"),
            "bday": DateAttribute(),
            "role": Attribute(),
            "img": Attribute(),
            "isActive": Attribute().serializeAs("is-active")
        ])
    }
}
  • further check it with Leak XCode instrument and got a lot of leaks (~60):

1c4abcb7134a27a0f8abf995b5a2df30

be0e3e9b101a1b51bd4000338dd890ea

Do you have any suggestions how to fix it? Thanks

@vpetrenko90
Copy link
Author

vpetrenko90 commented Feb 5, 2017

Another leak stack trace related to ValueFormatters, looks like the issue is here:

	static func defaultRegistry() -> ValueFormatterRegistry {
		var directory = ValueFormatterRegistry()
		//directory.registerFormatter(URLValueFormatter()) // when comment it -> no leak
		//directory.registerFormatter(DateValueFormatter())
		//directory.registerFormatter(BooleanValueFormatter())
		return directory
	} 

a3b9d75cd362bbe56295ee74b33c702b

@vpetrenko90
Copy link
Author

@wvteijlingen any feedback would be appreciated, thanks!

@piogab
Copy link

piogab commented Feb 8, 2017

We have also noticed similar problems recently

@wvteijlingen
Copy link
Owner

Thanks for reporting this @ameli90! These definitely need to be fixed. Unfortunately I don't have much time to work on Spine now (hence also this late response). I'll see what I can do, but feel free to submit a PR if you have time to work on it :).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants