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

[SR-3261] memory not freed after call deallocate on UnsafeMutablePointer #4439

Open
swift-ci opened this issue Nov 23, 2016 · 1 comment
Open

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-3261
Radar None
Original Reporter xray (JIRA User)
Type Bug
Environment

swift 3
xcode 8.1

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug, Leak
Assignee None
Priority Medium

md5: 0efef760cf6c02546b8e6f8f83d55510

Issue Description:

Both Xcode memory report and instruments can't detect memory freed by deallocate, instruments also report memory leak. here's simple code to reproduce

struct Test {
    
    var ptrToInt: UnsafeMutablePointer<Int>
    
    init() {
        ptrToInt = UnsafeMutablePointer<Int>.allocate(capacity: 1)
        ptrToInt.initialize(to: 42)
    }
    
    func deleteValue() {
        ptrToInt.deinitialize(count: 1)
        ptrToInt.deallocate(capacity: 1)
    }
}

var x = [Test]()
var i = 0;
while(i < 1000000) {
    i = i + 1
    x.append(Test())
}
while(i > 0) {
    i = i - 1
    x.popLast()?.deleteValue()
}

the memory never goes down when it finished. and instruments gives a lots memory leak.

@belkadan
Copy link

belkadan commented Dec 9, 2016

I don't see this behavior on master. Are you sure you're not just seeing the array itself as the leftover memory? But that wouldn't show up as "lots of leaks" in Instruments.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants