Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I manually zero out memory?

Tags:

Is it possible to manually clear out the contents of an object from memory?

In particular, I'm dealing with NSData. I've tried using data.length = 0 and data.setData(NSData).

I know ARC will come in and clean up after it is out of scope to whom it belongs, but is it possible to manually force this process when I want?

like image 958
David Biga Avatar asked Jun 10 '16 17:06

David Biga


People also ask

How do you zero out RAM?

Restart your device Since RAM is short-term data that only exists for programs that are currently running, restarting your device will clear your RAM. Some processes may be running in the background without your knowledge, and a restart is a sure way to tell those processes to stop and give your RAM a break.

Does Linux zero out memory?

No, Linux does not zero its menory after releasing it. Most libraries implement zeroing the memory while allocating it, but this is programming language dependent and can be overridden.


1 Answers

I think you have some misconceptions about ARC I'd like to clear up. The goal of ARC is is to ensure memory leaks don't occur. It's responsible for tracking the object over its life cycle, and ensuring it's "freed" when no references remain to it.

It's important to note that the memory being "freed" does not imply "writing over it all with 0s".

It simply means that memory will be designated as unused. The freed memory becomes a candidate for allocation when the system needs to allocate memory to new objects.

There's no guarentee, however, that this reallocation will happen, thus it's very possible for your freed memory to contain your original data, and never be overwritten.

like image 67
Alexander Avatar answered Oct 05 '22 22:10

Alexander