How to secure dealloc memory for objectiveC Strings in iOS?
I am pretty new in iOS development and I have the following question: In my code I have a UIViewController with a UIText field that will hold a password when user will type in the view. The password is used for authentication in front a server:
UItextField* txtPassword;
[myClass loginWithPassword:txtPassword.text];
After using it I want to be sure that there are no leftovers of the password in the memory, so an attacker won't be able performing a memory dump of the iPhone and extracting from it the password.
In windows for 开发者_Python百科example I could use the SeucreZeroMemory function for filling a block of memory with zeros.
What is the best way doing it for iOS? Who is responsible to free the UItextField*
string, and is it enough?
What you want is really not needed, you don't need to write zeros over you allocated data to be sure that it is secure. The reason is that no one but you can access the memory and iOS uses address space randomization so even if it would be possible to get your memory, its hard to guess where your data is (and if one don't know where the data is, it is hard to guess what exactly the data is, luckily the RAM has no filesystem that helps in such a case).
The second thing is, if you use [foo release]
and you textfield gets deallocated in this process, the OS reclaims the memory. Now the OS will always fill new memory pages with zeroes before giving it to the asking process, so you don't have to fear that there is an malicious app that just allocates memory in the hope it finds the password this way.
ok, Release your object which store the password in your class by going into the dealloc methods. Or release when ever the use that object is finished.by writing this [object release]; I hope it will help you .
精彩评论