I had to mention that I have lua script 40kB size. Would it make any memory problem?
That depends on how much your camera has free to start with.
The CHDK function get_meminfo() will give you information about how much memory is available.
The most relevant values are free_size and free_block_max_size. These values are in bytes. There isn't a specific known minimum you need free, but if the canon system heap goes below a few hundred KB, you are likely to start getting crashes. CHDK will use other heaps (ARAM or EXMEM) before using the system heap, so if those still have substantial free space, you don't need to worry about reducing the script memory usage.
The lua function collectgarbage('count') will return the amount of memory used by lua, in kilobytes. This does
not include the script source. Depending on your script, you may find that calling collectgarbage('step') or collectgarbage('collect') occasionally is required to keep Lua memory use under control. This is particularly true of scripts that generate a lot of unique strings.