How to stop and iPhone from automatically cleaning data from apps?

Whenever an iPhone gets close to being full, it automatically cleans documents and data from random apps. This is really annoying because it deletes any music that I about on the app store. However, recently, it deleted a ton of data from an online game that mostly updates through downloading in game rather than through the app store. Is there any way to stop it from doing this?

Clearly have you phone set to automatically sync - so it is doing what you asked it to - purging old thing to make room for new. First, go thru your phone and delete or at least offload the things you do not use all the time. Then run something like Dr. Cleaner - several passes - to remove artifacts and abandoned fragments. Plug you phone into your computer, and change the setting to MANUALLY manage music, purchases, etc. You can also store a lot in various free Clouds. Make sure you have auto backup set to the Cloud - unless you are going to remember to back up your phone all the time to your won computer ( which you should do every so often, anyway.) And gotta ask - are you sure you have Find My Phone enabled? Running a VPN? Got something like Secure ME on the phone, so free Wi-Fi does not plant nasty things in your phone?

General advice to you - who is blaming the PHONE for your own lack of info - is RTFM.

Now you know why I'm a Windows person and you can't pay me enough money to own an Apple product