iAds and AdMob Increasing App Size

On iOS, under Settings > General > Usage > Manage Storage, my app takes around 800KB of “Documents & Data”.

If I put iAds into my app and call a banner ad, then the size jumps to 4.1MB and remains there.

If I use AdMob and do the same thing, the size jumps to ~6MB, and then steadily increases. (Sometimes, it will go to 1.8MB or so, then when I return to the app, it’ll jump to ~6MB.) Quitting the app and then restarting will bring the size down a bit, but usually not back to the start size. It’s the same code as the iAds though, so I don’t know why only AdMob would increase.

All the ads are test ads.

Does anyone know why this is happening? Does showing these ads need >4MB of space? Is there a way to clear this memory before closing the app?

There’s not much to my ads, but the basic flow is this:

In main.lua,
On app start: initialize ads, show banner
On app suspend: hide ads
On app resume: show banner
On app exit: hide ads

Thanks in advance!

Your app size will increase, because you’re including plugin libraries that increase the code size. AdMob is particularly large.  AdMob may be downloading rich HTML files which might kept in your temporary storage areas.

Rob

Hi Rob, thanks for the reply!

My app size increases by 2.2MB when I include both iAds and AdMob in my build settings, which makes sense.

But the thing that worries me is that the size of the Documents & Data increases so much. In addition to the 2.2MB increase in app size, for iAds, the first time the app receives a banner ad and I call ads.show(), the Documents & Data size increases by 3MB, and for AdMob, it increases by at least 4MB (and then keeps increasing every time ads.show() is called and every ad refresh from what I can tell). This seems odd.

Is there any way to clear the memory used by the ads in the temporary storage?

Ok, so I created this quick example to demonstrate how Documents & Data grows.

main.lua:

[lua]

local composer = require(“composer”)
local ads = require(“ads”)

local adMobAppID_iOS_Banner = “ca-app-pub-MY_ADMOB_ID”

local function adMobListener(event)
    print("**** AdMob Phase: "… event.response)
end

ads.init(“admob”, adMobAppID_iOS_Banner, adMobListener)

ads.show(“banner”, {x=0, y=0, testMode=true })

composer.gotoScene(“menu”)

[/lua]

menu.lua is just an empty scene with nothing in it

Documents & Data size
Without any ads: 88 KB
With ads initializing: 320 KB
Running now with ads.show() called once:

  • 2.6 MB after 10 min of usage
  • 1.3 MB after quitting
  • 2.9 MB after 15 min
  • 1.7 MB after quitting
  • 3.8 MB after 15 min
  • 2.2 MB after quitting

So the Documents and Data size grew from 320 KB to 2.2 MB after 40 minutes of use and will continue to grow the longer I use the app. It will not go back down to the start value despite quitting and restarting.

I am using an iPhone 6 with iOS 8.3. AdMob banner ads are test ads with a refresh rate of 30 seconds.
I’ve tried deleting the files in the system.TemporaryDirectory folder upon app suspend and exit, but that doesn’t reduce the size, so it seems the ads are not being stored there.

Any clue on how to delete them so the Documents & Data stops growing? Or is this a memory leak?

Thank you

Well, it’s not a “memory” leak, but perhaps a storage leak.  Still these are not numbers to be worried about.  Files that build up in system.TemporaryDirectory will be purged by the system when it needs space.

But if you’re concerned you can use the “lfs” module which will let you get a listing of files in the various directories that you have access to and see what’s there. Once you have the file names, you can clean them up yourself.

Rob

Hi Rob,

I did as you suggested and went through the files. Attached is the code that worked for me. Documents & Data is no longer indefinitely increasing.

For Android, I’m removing the files in the app_webview/Cache folder.

For iOS, I’m removing Cache.db, Cache.db-wal, and the files in fsCachedData.

Are there any repercussions to doing this? As far as I can tell, only the ad networks are using these files in my app, but I can’t be 100% sure…

[lua]

– CLEAR CACHED ADS ----------------------------------------------------------------------
function clearCachedAds()
    local lfs = require “lfs”
    local bundleID = my_bundle_id
    local path = system.pathForFile("", system.CachesDirectory)
    
    – Android Interstitial (haven’t tested Banner ads)
    if (system.getInfo(“platformName”) == “Android”) then
        path = string.sub(path, 1, string.len(path)-13)
        
        – Remove all files in /data/data/com.package_name/app_webview/Cache
        path = path … “/app_webview/Cache”
        if lfs.chdir(path) then
            for file in lfs.dir(path) do
                os.remove(path … “/” … file)
            end
        end
        
    – iOS Banner & Interstitial
    elseif (system.getInfo(“platformName”) == “iPhone OS”) then
        path = string.sub(path, 1, string.len(path)-7)
        path = path … “/” … bundleID
            
        – Remove Library/Caches/my_bundle_id/Cache.db
        os.remove(path … “/Cache.db”)
        
        – Remove Library/Caches/my_bundle_id/Cache.db-wal
        os.remove(path … “/Cache.db-wal”)
        
        – Remove all files in Library/Caches/my_bundle_id/fsCachedData
        path = path … “/fsCachedData”
        if lfs.chdir(path) then
            for file in lfs.dir(path) do
                os.remove(path … “/” … file)
            end
        end
    end
end
[/lua]

The OS should take care of it for you over time.  Also, since you’re killing cache files, you are going to hit network resources more often that might not be necessary.  For instance if you add Facebook support and you want to download friend’s avatars and you blow away the cache, then you will always be downloading images from Facebook which will impact performance.  But if ads are your lone network activity, there shouldn’t be any other ramification.

Rob

Your app size will increase, because you’re including plugin libraries that increase the code size. AdMob is particularly large.  AdMob may be downloading rich HTML files which might kept in your temporary storage areas.

Rob

Hi Rob, thanks for the reply!

My app size increases by 2.2MB when I include both iAds and AdMob in my build settings, which makes sense.

But the thing that worries me is that the size of the Documents & Data increases so much. In addition to the 2.2MB increase in app size, for iAds, the first time the app receives a banner ad and I call ads.show(), the Documents & Data size increases by 3MB, and for AdMob, it increases by at least 4MB (and then keeps increasing every time ads.show() is called and every ad refresh from what I can tell). This seems odd.

Is there any way to clear the memory used by the ads in the temporary storage?

Ok, so I created this quick example to demonstrate how Documents & Data grows.

main.lua:

[lua]

local composer = require(“composer”)
local ads = require(“ads”)

local adMobAppID_iOS_Banner = “ca-app-pub-MY_ADMOB_ID”

local function adMobListener(event)
    print("**** AdMob Phase: "… event.response)
end

ads.init(“admob”, adMobAppID_iOS_Banner, adMobListener)

ads.show(“banner”, {x=0, y=0, testMode=true })

composer.gotoScene(“menu”)

[/lua]

menu.lua is just an empty scene with nothing in it

Documents & Data size
Without any ads: 88 KB
With ads initializing: 320 KB
Running now with ads.show() called once:

  • 2.6 MB after 10 min of usage
  • 1.3 MB after quitting
  • 2.9 MB after 15 min
  • 1.7 MB after quitting
  • 3.8 MB after 15 min
  • 2.2 MB after quitting

So the Documents and Data size grew from 320 KB to 2.2 MB after 40 minutes of use and will continue to grow the longer I use the app. It will not go back down to the start value despite quitting and restarting.

I am using an iPhone 6 with iOS 8.3. AdMob banner ads are test ads with a refresh rate of 30 seconds.
I’ve tried deleting the files in the system.TemporaryDirectory folder upon app suspend and exit, but that doesn’t reduce the size, so it seems the ads are not being stored there.

Any clue on how to delete them so the Documents & Data stops growing? Or is this a memory leak?

Thank you

Well, it’s not a “memory” leak, but perhaps a storage leak.  Still these are not numbers to be worried about.  Files that build up in system.TemporaryDirectory will be purged by the system when it needs space.

But if you’re concerned you can use the “lfs” module which will let you get a listing of files in the various directories that you have access to and see what’s there. Once you have the file names, you can clean them up yourself.

Rob

Hi Rob,

I did as you suggested and went through the files. Attached is the code that worked for me. Documents & Data is no longer indefinitely increasing.

For Android, I’m removing the files in the app_webview/Cache folder.

For iOS, I’m removing Cache.db, Cache.db-wal, and the files in fsCachedData.

Are there any repercussions to doing this? As far as I can tell, only the ad networks are using these files in my app, but I can’t be 100% sure…

[lua]

– CLEAR CACHED ADS ----------------------------------------------------------------------
function clearCachedAds()
    local lfs = require “lfs”
    local bundleID = my_bundle_id
    local path = system.pathForFile("", system.CachesDirectory)
    
    – Android Interstitial (haven’t tested Banner ads)
    if (system.getInfo(“platformName”) == “Android”) then
        path = string.sub(path, 1, string.len(path)-13)
        
        – Remove all files in /data/data/com.package_name/app_webview/Cache
        path = path … “/app_webview/Cache”
        if lfs.chdir(path) then
            for file in lfs.dir(path) do
                os.remove(path … “/” … file)
            end
        end
        
    – iOS Banner & Interstitial
    elseif (system.getInfo(“platformName”) == “iPhone OS”) then
        path = string.sub(path, 1, string.len(path)-7)
        path = path … “/” … bundleID
            
        – Remove Library/Caches/my_bundle_id/Cache.db
        os.remove(path … “/Cache.db”)
        
        – Remove Library/Caches/my_bundle_id/Cache.db-wal
        os.remove(path … “/Cache.db-wal”)
        
        – Remove all files in Library/Caches/my_bundle_id/fsCachedData
        path = path … “/fsCachedData”
        if lfs.chdir(path) then
            for file in lfs.dir(path) do
                os.remove(path … “/” … file)
            end
        end
    end
end
[/lua]

The OS should take care of it for you over time.  Also, since you’re killing cache files, you are going to hit network resources more often that might not be necessary.  For instance if you add Facebook support and you want to download friend’s avatars and you blow away the cache, then you will always be downloading images from Facebook which will impact performance.  But if ads are your lone network activity, there shouldn’t be any other ramification.

Rob