it used to be a pointer, but setting it to nil no longer worksIsn't the 'array' just a pointer to memory? Correct me where I'm wrong, but it should be covered by ARC. If needed, you can check the type of hold it has (weak, strong, ...).
If it's a larger array and you want the memory, look into how and where it's held. You could check by calling a reference to the array and see if it's defined or not.
hmm you do make a pointWhy would you need to delete it completely from memory? If it's a property of the class then your can't 'delete it' you can only clear all the values so it is empty. If it's a local property in a method, then it will be deleted when the method ends, again I don't think you can delete it, just remove all the values from it.
Post your code that declares the variable. If it's not declared as an optional, then try that.hmm you do make a point
still curious why it could be done in Objective-C and no longer in Swift
Could you elaborate on that?Post your code that declares the variable. If it's not declared as an optional, then try that.
You should probably review how Swift uses nil, and what it means for a var to be optional, as distinct from vars that aren't optional. Swift and Obj-C use nil in different ways.
Apple seems to be a bit reluctant what nil is nowadaysPost your code that declares the variable. If it's not declared as an optional, then try that.
You should probably review how Swift uses nil, and what it means for a var to be optional, as distinct from vars that aren't optional. Swift and Obj-C use nil in different ways.
As long as you no longer have any other objects referencing the array in your code then it should automatically dealloc itself because of automatic reference counting, assuming you aren't having an issue with a reference cycle.Apple seems to be a bit reluctant what nil is nowadays
they say it's an absence of value
this would imply it is still a pointer without referenceAs long as you no longer have any other objects referencing the array in your code then it should automatically dealloc itself because of automatic reference counting, assuming you aren't having an issue with a reference cycle.
And what's the problem with that? You don't need to manually delete a pointer. That's all taken care of for you.this would imply it is still a pointer without reference
And what's the problem with that? You don't need to manually delete a pointer. That's all taken care of for you.
EDIT: Actually what is the point of deleting the array? Why bother even deleting the items in the array at all?
I do not have a problem if it were a pointerAnd what's the problem with that? You don't need to manually delete a pointer. That's all taken care of for you.
EDIT: Actually what is the point of deleting the array? Why bother even deleting the items in the array at all?
Not necessarily. Depends on the lifetime of the array which leads me to my question...Memory constraints!
I do not have a problem if it were a pointer
Problem is I can't find any reference stating it's a pointer
var myArray : int?[] = [nil, nil, 3]
The array is a Stored Variable Property in the ViewController. I guess making it an optional is the way to go. Giving the optional the nil value does not clear the memory entirely though as an optional is an enum anyways.Not necessarily. Depends on the lifetime of the array which leads me to my question...
Forget pointers. Where is your array anyways? Inside a function, a class, global scope, etc.?
Because I took a look at this, I didn't see anything about it, except for that once an object has no reference it gets deleted (duh). Why would you waste time setting all the values to 0 or whatever.
I did find that you can set an array's members to nil if you use the '?' (optional) flag.
Code:var myArray : int?[] = [nil, nil, 3]
But you're trying to clear up the memory taken up by the array in memory. You can't really do that. Question is what is the array for and is there a reason you have to delete its contents in the first place?
var myArray : [Int]? = [0,1,2]
myArray = nil