0

I have found a application has Clean Memory function.

enter image description here

I think it uses the original PURGE function, but after checking (using Activity Monitor), I see that it's likely to be more free File Cache than Purge command (or it can operate independently of the PURGE command). Please refer my experiment in below.

  1. Below is first information in Activity Monitor

enter image description here

  1. Then, I use Clean Memory function (FREE UP 600+ MB File Cache)

enter image description here

  1. Finally, I use PURGE command (FREE UP more 400+ MB File Cache)

enter image description here

My question: Refer free mem as function of command 'purge'
1. What it has used technology to make Clean Memory function (I have research https://opensource.apple.com/ for a week but did not find relevant information)?
2. (optional) The difference between Clean Memory function and PURGE command?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Huynh Inc
  • 2,010
  • 1
  • 25
  • 42
  • 1
    http://stackoverflow.com/questions/1150650/is-it-ok-to-use-classic-malloc-free-in-objective-c-iphone-apps try malloc(), free() from NSData or NSMutableData –  Mar 15 '15 at 13:20

2 Answers2

2

What the Memory Clean application seems to do is just to allocate memory and release it. If you have Xcode you can run Instruments and track the allocations of Memory Clean. As soon as you hit the "Clean Memory" button you will see in Instruments that the allocated "Total Bytes" are nearly the same as the one displayed as "free memory available" in Memory Clean. You can see the same in the Activity Monitor as well.

About the purge command, it seems to use different mechanism. Tracing it with dtruss (dtruss purge) shows the following result on the last line:

vfs_purge(0x7FFF5320CDE8, 0x7FFF5320CDF8, 0x7FFF5320CE48)        = 0 0

According to the source of vfs_syscalls, and more specifically the comments:

/* * Purge buffer cache for simulating cold starts */

Needless to say, purging file cache is a bad idea and it has only one good application - benchmarking disks.

VolenD
  • 3,592
  • 18
  • 23
  • 1
    Tks for comment, can you expalin more detail about "allocate memory and release it"? How to do it? – Huynh Inc Mar 11 '15 at 01:54
  • 1
    There are many ways to do this, but probably the fastest one is `malloc()`. You can check the [following question](http://stackoverflow.com/questions/1150650/is-it-ok-to-use-classic-malloc-free-in-objective-c-iphone-apps). – VolenD Mar 11 '15 at 08:26
0

I have found my solution.

It's simple create data then release it.

Huynh Inc
  • 2,010
  • 1
  • 25
  • 42