Wish One way to save memory (RAM)

LucaMs

Expert
Licensed User
Longtime User
Given that we are in a mobile environment, it would be very useful to exclude some unused "objects" (functions) at compile time (or pre-compile).

I do not think that is possible obtain that the compiler makes this thing. It could do it (well, perhaps a precompiler) from classes or modules.

For this reason, I would suggest everyone to post more classes and less libraries.

There are no "Singleton" classes in B4a, right? You can use the modules, right?
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
The compiler will warn you about unused variables. It is your responsibility to clear them.

Note that the memory usage of unused variables is insignificant.


Yes.

Sorry, Erel, i meant unused Subs (functions).

For example, you may occasionally need a mathematical function and load an entire math library when other do not need.
 

Informatix

Expert
Licensed User
Longtime User
For this reason, I would suggest everyone to post more classes and less libraries.

It is not always a choice. All my libraries are written in Java and I couldn't make B4A classes doing the same. Moreover, I'm not sure there's a real benefit in tracking and cleaning the unused functions (if not done automatically) because 99% of libraries for B4A have a size under 1MB, and a lot of them are even under 200 KB. Sparing 100 KB in the best case is not worth the time spent.
The only case that really bothers me is the Phone library. It does a lot of different things (too much to my taste) and, when you just want to know the version of Android or set a wake lock, for example, you get in your APK all the code to send and receive SMS, and I don't like when security apps report that my app can send SMS for this stupid reason. So I created many small libraries to call the same functions.
 

LucaMs

Expert
Licensed User
Longtime User
It is not always a choice. All my libraries are written in Java and I couldn't make B4A classes doing the same. Moreover, I'm not sure there's a real benefit in tracking and cleaning the unused functions (if not done automatically) because 99% of libraries for B4A have a size under 1MB, and a lot of them are even under 200 KB. Sparing 100 KB in the best case is not worth the time spent.
The only case that really bothers me is the Phone library. It does a lot of different things (too much to my taste) and, when you just want to know the version of Android or set a wake lock, for example, you get in your APK all the code to send and receive SMS, and I don't like when security apps report that my app can send SMS for this stupid reason. So I created many small libraries to call the same functions.


"...you get in your APK all the code to send and receive SMS... "
and potential customers do not install it.

You're absolutely right
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Just to make sure that it is clear, the SMS permission is not added when you add the Phone library. You will not lose potential customers.

Informatix refers to a specific scanning app that mistakenly reported an app as using SMS because of the SMS code. This is however a mistake as it is not possible to send SMS without the permission. Other than that app there were never any such reports.
 

LucaMs

Expert
Licensed User
Longtime User
Just to make sure that it is clear, the SMS permission is not added when you add the Phone library. You will not lose potential customers.

Informatix refers to a specific scanning app that mistakenly reported an app as using SMS because of the SMS code. This is however a mistake as it is not possible to send SMS without the permission. Other than that app there were never any such reports.

This is a good information, given that the Phone library is practically indispensable .

Thanks
 

Informatix

Expert
Licensed User
Longtime User
"...you get in your APK all the code to send and receive SMS... "
and potential customers do not install it.

People cannot know that without installing the application and using a specific tool so it's not a major concern. It's just that we cannot control how clever the security apps are and I prefer to remove any code that's not related at all with my app and could be seen as a potential nuisance (it's not like a Math library whose a few computing functions are never called).
 

Informatix

Expert
Licensed User
Longtime User
Informatix refers to a specific scanning app that mistakenly reported an app as using SMS because of the SMS code. This is however a mistake as it is not possible to send SMS without the permission. Other than that app there were never any such reports.
Exactly. And the creator of this app never changed this despite my reports (it looks like a dead project now so that will probably never change). Anyway, my point of view about the Phone library was not different before this tool exists (and my own libs to replace Phone are not new). This lib mixes things that have nothing in common. IMHO it really deserves to be splitted in smaller and more coherent parts.
 

antonomase

Active Member
Licensed User
Longtime User
when you just want to know the version of Android
Why not a separation between a "device" library for functions which are common to tablets and phones and a "phone" library which specific functions like sms ?
 

sorex

Expert
Licensed User
Longtime User
conditional includes or even worse conditional inside each include is hard to implement.

would be nice if it could but it would also mean slower compile time.
When I look at simple apps on the market I see APK of 70Kb
an empty B4A project is just anout 100K.

just an example, a simple call fowarding app that just dials *21*number# with a hardcoded number (no gui at all)

libs:
core
phone
stringutils for changing # to %23 the urlencode way

apk is already ~210K while using just 2 functions from the libs.

Not that it matters that much in times of broadband connections but if you add a few libs it adds up very quickly while most of the code isn't even used.
 

LucaMs

Expert
Licensed User
Longtime User
conditional includes or even worse conditional inside each include is hard to implement.

would be nice if it could but it would also mean slower compile time.
When I look at simple apps on the market I see APK of 70Kb
an empty B4A project is just anout 100K.

just an example, a simple call fowarding app that just dials *21*number# with a hardcoded number (no gui at all)

libs:
core
phone
stringutils for changing # to %23 the urlencode way

apk is already ~210K while using just 2 functions from the libs.

Not that it matters that much in times of broadband connections but if you add a few libs it adds up very quickly while most of the code isn't even used.


...while most of the code isn't even used...

This was just what I said at the beginning.

The ideal would be to use only code (classes), and when the project is completed, go to remove all unused routine (also, IDE could do this job, since it reports them)
 

sorex

Expert
Licensed User
Longtime User
but then it needs to parse all the library code aswell, I think it now just copies the precompiled jar into the project.

so compile times will grow a lot I'm affraid.
 
Top