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

memory leaks #82

Closed
a72 opened this issue Feb 21, 2019 · 2 comments
Closed

memory leaks #82

a72 opened this issue Feb 21, 2019 · 2 comments

Comments

@a72
Copy link

a72 commented Feb 21, 2019

This code causes a memory leak.
If I use JSON decoder then there is no memory leak.
Any idea how to fix this?

import Foundation
import CSV

typealias  TestCodable = Test & Codable

protocol Test {
    func baz()
}

struct Product1:TestCodable {
    var title:String
    var price:Int
    var quantity:Int
    func baz() {
        print(title)
    }
}

let csv = """
title,price,quantity
Nike,10,1
Nike1,11,1
Nike2,12,1
Nike3,13,1
Nike4,13,1
Nike5,13,1
Nike6,13,1
"""

let json = """
{
"title": "Nike",
"price": 10,
"quantity": 1
}
"""
let data = json.data(using: .utf8)!
var arrayProduct: [Test] = []
let reader = try CSVReader(string: csv, hasHeaderRow: true)
let decoder = CSVRowDecoder()

while reader.next() != nil {
//    let product: Product1 = try! JSONDecoder().decode(Product1.self, from: data)
    let product = try! decoder.decode(Product1.self, from: reader)
    arrayProduct.append(product)
    print("\(product)")
    sleep(4)
}
@a72
Copy link
Author

a72 commented Feb 21, 2019

image

@a72
Copy link
Author

a72 commented Apr 16, 2019

swift 5 solved the problem

@a72 a72 closed this as completed Apr 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant