B4J Question CustomiListView out of memory

fengce

Member
If B4XTable or xChart are added separately in the CustomiListView, there will be no error. If both B4XTable and xChart are added at the same time, there will be a memory overflow phenomenon.I cann't release objects. Perhaps my code was not written correctly,could anybody give me some advice to fix to the problem.
 

Attachments

  • Project.zip
    15.7 KB · Views: 68

Brian Michael

Member
Licensed User
Hi, its better if you post the error log.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
could anybody give me some advice to fix to the problem.
Comment the line : Sleep(0)
300 iterations of simultaneous xChart and B4XTable. No crash. If you are still having trouble, I can upload you the project
B4A: It took 64 sec on tablet when that line is not commented .
If we comment the line, it took: 15 secs

B4J: On a pc that is not really fast: 6 sec when commented sleep(0). and 32 secs when not commented
 
Upvote 0

fengce

Member
Thanks for Brian Michael and Mahares .I'm glad you replied to me.
I havn't fixed the problem yet,if I Comment the line : Sleep(0) ,the memory will grow bigger and bigger till crash,if not Comment the line : Sleep(0), in the debug mode, the IDE will report the errors. What should I do. waiting for help. Thank you for replying to me
 

Attachments

  • error log.txt
    6.5 KB · Views: 53
  • Memory usage is constantly increasing.png
    Memory usage is constantly increasing.png
    286.7 KB · Views: 65
  • Demo.zip
    16.4 KB · Views: 55
Upvote 0

Mahares

Expert
Licensed User
Longtime User
waiting for help
The project you posted in the previous post is very different from the project in post #1 you have. Nevertheless, I modified your latest project you have in post #4 and made a complete B4J project that displays the xCharts and the B4XTables inside the XClv ( 500 of them) at the same time. I used lazy loading and you will see in the attached project, it shows you both instantly. I used 500 iterations like you wanted in your previous post.
 

Attachments

  • xClvWIthxChartAndB4XTable InsideModifiedByMaharesWithLL.zip
    18.2 KB · Views: 61
Upvote 0

fengce

Member
The project you posted in the previous post is very different from the project in post #1 you have. Nevertheless, I modified your latest project you have in post #4 and made a complete B4J project that displays the xCharts and the B4XTables inside the XClv ( 500 of them) at the same time. I used lazy loading and you will see in the attached project, it shows you both instantly. I used 500 iterations like you wanted in your previous post.
Dear Sir,
Thank you very much for modifying the code, which has greatly inspired me.You are a warm and friendly person. Your help has deepened my understanding of b4x. In addition, I would like to ask how to release items loaded in the customlistview(500 iterations and VISIBLE in the CLV) and reduce memory usage. In my project, I can remove these items, but I cannot free up memory usage. Can you give me some suggestions? Thanks again!
 
Last edited:
Upvote 0

fengce

Member
500 iterations
The project you posted in the previous post is very different from the project in post #1 you have. Nevertheless, I modified your latest project you have in post #4 and made a complete B4J project that displays the xCharts and the B4XTables inside the XClv ( 500 of them) at the same time. I used lazy loading and you will see in the attached project, it shows you both instantly. I used 500 iterations like you wanted in your previous post.
I'v tested your project , and if I only iterate 500 times in XCLV, there will be no errors and the memory usage is not high,It works good what i want. However, if the scrollbar is moved to display items, the memory usage will increase more and more。As the number of items displaying increased , an error will be shown in the IDE logs and the program is no longer working.
Many thanks for your kind help!
 

Attachments

  • error log.txt
    133.1 KB · Views: 57
Upvote 0

Mahares

Expert
Licensed User
Longtime User
an error will be shown in the IDE logs and the program is no longer working.
I have not experienced that error you reported in your previous post. I scrolled several times and no memory problem. That is the purpose of lazy loading . it releases memory. Maybe someone who has downloaded it and seen what you saw can report. See screenshot. I was able to go to the 500th item and scroll back to item 1 several times with no problems

1681209717864.png
 
Last edited:
Upvote 0

fengce

Member
I have not experienced that error you reported in your previous post. I scrolled several times and no memory problem. That is the purpose of lazy loading . it releases memory. Maybe someone who has downloaded it and seen what you saw can report. See screenshot. I was able to go to the 500th item and scroll back to item 1 several times with no problems

GIF 2023-4-12 14-04-53 (1).gif


Screenshot 2023-04-12 142419.png

I captured the screen,please have a look. I wanna reduce the memory usage by using clv.clear,but no effection,don't know how to deal with the problem.What I want to achieve is to completely release resources when I'm not using CLV. thanks for your reply,best regards!
 
Upvote 0

Brian Michael

Member
Licensed User
In programming it is good to work wisely.
I think loading all the data at the same time is a bad idea since as you can see it clutters the device running it.
Imagine if that is with your PC that has good features vs a not so good computer.
You should create pagination and load a delimited number of data at a time.

This is just a piece of advice, I created an app where I had the same problem until I started working in a segmented way.

You can also try with B4X PreOptimizedCLV: https://www.b4x.com/android/forum/t...loading-extension-for-xcustomlistview.115289/
 
Upvote 0

fengce

Member
In programming it is good to work wisely.
I think loading all the data at the same time is a bad idea since as you can see it clutters the device running it.
Imagine if that is with your PC that has good features vs a not so good computer.
You should create pagination and load a delimited number of data at a time.

This is just a piece of advice, I created an app where I had the same problem until I started working in a segmented way.

You can also try with B4X PreOptimizedCLV: https://www.b4x.com/android/forum/t...loading-extension-for-xcustomlistview.115289/
Thank you for your suggestion. I will improve my project according to the ideas you provided. Thank you again for your enthusiastic response these days, which has boosted my confidence in using b4x to develop programs.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I created an app where I had the same problem
@Brian Michael, you can be of big help to the OP to test the project I posted in post #5 to see if you experience the same issues the OP has had, because I did not see any memory issues when I modified it and tested it extensively. Can you report back even with your changes if you think a code change will eliminate the problem the OP faced.. 500 items is a lot but with lazy loading , it is doable. It is not unsurmountable.
A word of advice to the OP, is perhaps he should run it in release mode and see if his memory problem still persists for him
 
Upvote 0
Top