Autoboxing, a little thing, can cause big problems for Android App Performance
To ensure your app performs well across a wide variety of
devices, you always try to use best practices. On that front memory optimization
is often a demanding task. Most of the time we always think on the bigger side
of it and miss the small thing that can add up to a big problem. Autoboxing is
a topic that often goes unnoticed when talking about performance issues.
Autoboxing is a great language feature, until you realize how
much of your performance is being lost to its convenience. You cannot imagine a
simple Autoboxing operations can easily tear through your Application’s memory.
What is
Autoboxing?
Till JDK 1.4, when we work with primitive types, it requires
repetitive work of converting the primitive types into wrapper classes and
vice-versa. Let’s say if we want to create a List with Integers, we have to
explicitly wrap them as Integer and we need to unwrap it to get int value.
So since JDK 1.5, Conversion from primitive types to
corresponding wrapper objects and vice versa can happen automatically.
Boxing: Conversion
of a primitive type to the corresponding reference type (int -> Integer).
Unboxing:
Conversion
of the reference type to the corresponding primitive type (Integer -> int).
How it
causes problem?
As we discussed Java provides corresponding wrapper classes
that match primitive types, and act as object wrappers. These classes give the
same functionalities as primitives but can be used with generic collections.
However their size in memory is not the same. An Integer object occupies 4
times more memory as primitive int.
In the example below, the API call adding a primitive int
value but the collection API takes Integer object. This assignment will perform
an Autoboxing operation from int to Integer object.
// Here is primitive variable
int value = 5;
List<Integer>
list = new ArrayList<>();
//autoboxing
to add primitive type (int) in collection class
list.add(value);
For a single call, this may not matter much. However, if we
are using it frequently, for example in an inner loop, it might occupy a lot of
memory unnecessarily and cause a big memory threat.
// Here is generic variable
Integer sum = 0;
for(int i= 0;i< 100;i++){
// autoboxing to
convert int into Integer
sum = sum + i;
}
As you can see in the above example, 100 new objects
allocation along with the sum calculation. But in case of primitive it doesn’t
require any additional allocation overhead.
This will also overhead
of more garbage collection and decrease the runtime performance. It can be
especially painful with data structures like HashMap. Let’s consider another code:
HashMap<Integer, String> map = new HashMap< >();
// Put the value in the map where key is primitive type.
map.put(1, "TestValue"); // expected key is Integer
type
// Get the value from the map where key is primitive type.
map.get(1); // expected key is Integer type
In the above code put and get operations will use Autoboxing
and cause additional load. Basically anytime you insert, update or retrieve a
value with this generic container when a primitive is involved you end up
boxing or unboxing values.
How to resolve
the problem?
To resolve the problem of autoboxing Android provided custom
containers SparseArrays and ArrayMap to use instead of traditional containers
like HashMap. These containers are design specifically to fight Autoboxing
problem and eliminate both runtime overhead and additional memory allocation. These
containers are more memory efficient than using a HashMap to map Integers to
Objects.
Below are the example code to create SparseArray:
SparseArray sparseArray = new SparseArray();
sparseArray.put(1, “Value1”);
SparseLongArray sparseLongArray = new SparseLongArray();
sparseLongArray.put(1, 1L);
SparseBooleanArray sparseBooleanArray = new
SparseBooleanArray();
sparseBooleanArray.put(1, true);
SparseIntArray sparseIntArray = new SparseIntArray();
sparseIntArray.put(1, 2);
This way you make your code more optimized and memory
efficient. To understand SparseArray and ArrayMap refer my detailed post.
How to
trace memory issues?
Android Studio provides profiling tools to records and compute
memory allocations of your app. Allocation Tracker are such a powerful tools
which shows object allocation and their size. It is also used to track memory
leaks.
Another good tool is Traceview, which is a graphical viewer
for execution logs that you create by using the Debug class to log tracing
information in your code
Conclusion
Now a day’s most of the applications are handling thousands of
data, so any optimization you make could potentially improve the performance
across our application. Small change of Autoboxing matters a lot for a mobile
developer where you have very limited memory and resources.
To find more interesting topics on Software development follow
me at:
This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
ReplyDeleteAndroid Online Training
wow A Wonderful website I like this blog very much.This blog can help lot of user to update their knowledge.Thanks for sharing this kind of blog.Anybody want to learn
ReplyDeletehttp://www.traininginannanagar.in/android-training-in-chennai.html
wow A Wonderful website I like this blog very much.This blog can help lot of user to update their knowledge.Thanks for sharing this kind of blog.Anybody want to learn
ReplyDeleteAndroid Training in Chennai
You have post an very useful blog about android. Its very interesting and useful to me and i have learn lots of new information from your blog share. keep update such kind of interesting stuff. thank you...
ReplyDeleteAndroid Training in Chennai
Your blog have a very nice informative content on Android Online Training
ReplyDeleteHi, your blog really nice, keep it up! I’ll go ahead and bookmark your website to come back later.
ReplyDeleteRegards,
Java Online Training | Java Online Training in India | Java Online Training India | Java Online Training in Hyderabad | Java Online Training Hyderabad | Java Training in Hyderabad | Java Training in India | Java Training Institutes in India | Java Training Institutes in Hyderabad | Java Course in Hyderabad | Java Training | Learn Java Online | Online Java Training | Best Java online Training Institutes in Hyderabad | Best Java Training Institutes in Hyderabad | Best Institutes for Java | Java Institutes in Hyderabad | Best Institutes for Java in Hyderabad | Learn Java | Java Training Institutes in Hyderabad | Java Certification | Java Certification Training | Java Certification Training in Hyderabad | Java Certification Training in India
Check it Through Android Online Training For more info.
ReplyDeleteNice Information Android Online Training, keep share
ReplyDeleteThe information related to the autoboxing is really informative... Wish to learn Android from the basics to the advanced level, enroll you in the Best Software Training Institute in Velachery to learn quickly...
ReplyDeleteAndroid Training Institute in Velachery | Best Android Training Institute in Velachery
Nice to read this article... Thanks for sharing.......
ReplyDeleteAndroid training
Nice information, check it once through Android Online Training for more info.
ReplyDelete
ReplyDeleteNice good info Android Online Training Hyderabad
Thanks for your article on Android technology. Android is an open source platform that allows developers to create stunning website loaded with various advanced features and functionalities. Android Training in Chennai | Android Course in Chennai
ReplyDeleteThank you so much for sharing this great blog.Very inspiring and helpful too.Hope you continue to share more of your ideas.I will definitely love to read.
ReplyDeleteAndroid Training in Chennai
Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this. Android Training in Chennai
ReplyDeleteAndroid Training Company Delhi | Android Trainer in Delhi
ReplyDeleteThanks for above information, I like it. check it once Android Online Training
ReplyDeletejava training
ReplyDeletejava training in chennai
best java training in chennai
java training institute in chennai
best java training center in chennai
The information which you have provided is very good. It is very useful who is looking for Java online training Hyderabad
ReplyDeletenice blog
ReplyDeletehadoop training in chennai
nice blog
ReplyDeleteandroid training in bangalore
ios training in bangalore
machine learning online training
Thanks for sharing such a great information..Its really nice and informative..
ReplyDeleteBest Software Training Centre in Chennai | Software Training Centre in Chennai
The information which you have provided is very good. It is very useful who is looking for selenium Online Training Bangalore
ReplyDeleteThis is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
ReplyDeleteAndroid Training In Chennai
Those rules moreover attempted to wind up plainly a decent approach to perceive that other individuals online have the indistinguishable enthusiasm like mine to get a handle on incredible arrangement more around this condition.
ReplyDeletefire and safety course in chennai
Nice blog..! I really loved reading through this article. Thanks for sharing such
ReplyDeletean amazing post with us and keep blogging... RPA Training in Chennai | Blue Prism Training in Chennai
This is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article.
ReplyDeleteapple ios training institutes in Hyderabad
ios app development in hyderabad
I believe there are many more pleasurable opportunities ahead for individuals that looked at your site. RPA Training in Chennai | Blue Prism Training in Chennai
ReplyDeleteGood Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
ReplyDeletePython Training in electronic city
DataScience with Python Training in electronic city
AWS Training in electronic city
Big Data Hadoop Training in electronic city
Devops Training in electronic city
React JS Training in electronic city
Selenium training in electronic city
core Java training in electronic city
Thank you for your post. This is excellent information. It is amazing and wonderful to visit your blog.
ReplyDeleteiPhone training courses in bangalore
ios app development course
ReplyDeleteNice blog..! I really loved reading through this article. Thanks for sharing such a amazing post with us and keep blogging...
Best Data Science online training in Hyderabad
Data Science training in Hyderabad
Data Science online training in Hyderabad
ReplyDeleteReally it was an awesome article… very interesting to read…
Thanks for sharing.........
Hadoop online training in Hyderabad
Hadoop training in Hyderabad
Bigdata Hadoop training in Hyderabad
myTectra Placement Portal is a Web based portal brings Potentials Employers and myTectra Candidates on a common platform for placement assistance
ReplyDeleteGreat Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
ReplyDeleteOnline DevOps Certification Course - Gangboard
Best Devops Training institute in Chennai
Really you have done great job,There are may person searching about that now they will find enough resources by your post
ReplyDeleteBest Devops training in sholinganallur
Devops training in velachery
Devops training in annanagar
Devops training in tambaram
Amazing blog about the various informative information on the programming languages... Java Training in Chennai | Pega Training in Chennai
ReplyDeleteHowdy, would you mind letting me know which web host you’re utilizing? I’ve loaded your blog in 3 completely different web browsers, and I must say this blog loads a lot quicker than most. Can you suggest a good internet hosting provider at a reasonable price?
ReplyDeleteBest AWS Amazon Web Services Training in Chennai | Best AWS Training and Certification for Solution Architect in Chennai
Amazon Web Services Training in Tambaram, Chennai|Best AWS Training in Tambaram, Chennai
It would have been the happiest moment for you,I mean if we have been waiting for something to happen and when it happens we forgot all hardwork and wait for getting that happened.
ReplyDeleteJava interview questions and answers
Core Java interview questions and answers
Java training in Chennai | Java training in Tambaram
Java training in Chennai | Java training in Velachery
Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.
ReplyDeletepython training institute in marathahalli
python training institute in btm
Python training course in Chennai
Nice blog. Thanks for explaining the Android concept, Autoboxing in detail. Keep sharing the latest updates about Android.
ReplyDeleteAndroid Application Development company in Coimbatore
iOS Application Development Company in Coimbatore
I am really impressed with your efforts and really pleased to visit this post.
ReplyDeleteData Science training in Chennai | Data Science Training Institute in Chennai
Data science training in Bangalore | Data Science Training institute in Bangalore
Data science training in pune | Data Science training institute in Pune
Data science online training | online Data Science certification Training-Gangboard
Data Science Interview questions and answers
Well researched article and I appreciate this. The blog is subscribed and will see new topics soon.
ReplyDeletepython course in pune
python course in chennai
python Training in Bangalore
Were a gaggle of volunteers as well as starting off a brand new gumption within a community. Your blog furnished us precious details to be effective on. You've got completed any amazing work!
ReplyDeleteJava training in Chennai | Java training institute in Chennai | Java course in Chennai
Java training in Bangalore | Java training in Electronic city
Java training in Bangalore | Java training in Marathahalli
Java training in Bangalore | Java training in Btm layout
Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
ReplyDeletebest rpa training in chennai
rpa training in chennai
rpa interview questions and answers
automation anywhere interview questions and answers
blueprism interview questions and answers
uipath interview questions and answers
rpa training in bangalore
Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
ReplyDeleterpa training in chennai
Best rpa training in bangalore
rpa course in bangalore
rpa training in marathahalli
rpa training in btm
best rpa training in chennai
Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.
ReplyDeleteAmazon web services Online Training |Best Online AWS Certification Course
AWS Training in Chennai | Advanced Amazon Web Services Training Institute in Chennai
AWS Training in Bangalore |Best AWS Training in Bangalore
Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.
ReplyDeleteAmazon web services Online Training |Best Online AWS Certification Course
AWS Training in Chennai | Advanced Amazon Web Services Training Institute in Chennai
AWS Training in Bangalore |Best AWS Training in Bangalore
Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.
ReplyDeleteAWS Online Training |Best Online AWS Certification Course
AWS Training in Chennai | Advanced Amazon Web Services Training Institute in Chennai
AWS Training in Bangalore |Best AWS Training Institute in Bangalore
Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.
ReplyDeleteAWS Online Training |Best Online AWS Certification Course
AWS Training in Chennai | Advanced Amazon Web Services Training Institute in Chennai
AWS Training in Bangalore |Best AWS Training Institute in Bangalore
Read all the information that i've given in above article. It'll give u the whole idea about it.
ReplyDeleteBest Devops online Training
Online DevOps Certification Course - Gangboard
Very good brief and this post helped me alot. Say thank you I searching for your facts. Thanks for sharing with us!
ReplyDeleteData Science course in Chennai | Best Data Science course in Chennai
Data science course in bangalore | Best Data Science course in Bangalore
Data science course in pune | Data Science Course institute in Pune
Data science online course | Online Data Science certification course-Gangboard
Data Science Interview questions and answers
Data Science Tutorial
This pretty much applies to every job profile. Dissatisfaction , politics and people expecting you to know and do everything . I believe job positions that are extremely close to business side of things will be more rewarding . Decisions you take and mistakes you make must have the shortest path to revenue impacts , That is a place where you will be respected.
ReplyDeleteJava training in Chennai | Java training institute in Chennai | Java course in Chennai
Thank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me
ReplyDeletePython Online certification training
python Training institute in Chennai
Python training institute in Bangalore
Amazing Article ! I have bookmarked this article page as i received good information from this. All the best for the upcoming articles. I will be waiting for your new articles. Thank You ! Kindly Visit Us @ Coimbatore Travels | Ooty Travels | Coimbatore Airport Taxi
ReplyDelete
ReplyDeleteWhoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.
aws training in bangalore
RPA Training in bangalore
Python Training in bangalore
Selenium Training in bangalore
Hadoop Training in bangalore
Amazing article. Your blog helped me to improve myself in many ways thanks for sharing this kind of wonderful informative blogs in live. I have bookmarked more article from this website. Such a nice blog you are providing ! Kindly Visit Us @ Best Travels in Madurai | Tours and Travels in Madurai | Madurai Travels
ReplyDeleteThe given information was excellent and useful. This is one of the excellent blog, I have come across. Do share more.
ReplyDeleteDevOps course in Chennai
Best DevOps Training in Chennai
Amazon web services Training in Chennai
AWS Certification in Chennai
Data Analytics Courses in Chennai
Big Data Analytics Courses in Chennai
DevOps Training in Anna Nagar
DevOps Training in T Nagar
Thanks For Sharing The Information The Information Shared Is Very Valuable Please Keep Updating Us Time Just Went On Reading The article Python Online Course Hadoop Online Course Aws Online Course Data Science Online Course
ReplyDeleteInformation from this blog is very useful for me, am very happy to read this blog Kindly visit us @ Luxury Watch Box | Shoe Box Manufacturer | Candle Packaging Boxes
ReplyDelete
ReplyDeleteThanks for sharing this wonderful and useful information...
AWS Training in bellandur
Marathahalli AWS Training Institues
Kalyan nagar AWS training in institutes
Data Science Training in bellandur
Data Science Training in Kalyan Nagar
Data science training in marathahalli
Wow...What an excellent informative blog, really helpful. Thank you so much for sharing such a wonderful article with us.keep updating..
ReplyDeletesalesforce Training in Bangalore
uipath Training in Bangalore
blueprism Training in Bangalore
Your post is just outstanding! thanx for such a post,its really going great and great work.
ReplyDeletepython training in kalyan nagar|python training in marathahalli
selenium training in marathahalli|selenium training in bangalore
devops training in kalyan nagar|devops training in bellandur
phthon training in bangalore
nice blog.keep on going.
ReplyDeletedata science course in Hyderabad with placements
very interesting informative post.Thanks you so much for the post and the tips for users.I love the post a lot and intreseted to know more about it
ReplyDeleteamazon webservices training institute in pune
The information provided is of great use as I got to learn new things. Keep Blogging.Best Android Training Institute
ReplyDeleteNice blog keep going..
ReplyDeleteSAP R3 services in India
SAP Hana services in India
PHP Development Services in India
Mobile Application Software Services in India
JAVA Development Services in India
SAP B1 services in India
Pretty! This was a really wonderful post. Thank you for providing these details.
ReplyDeleteadvanced java training institutes in bangalore
advanced java training in bangalore
best advanced java training institutes in bangalore
advanced java training course content
advanced java training interview questions
advanced java training & placement in bangalore
advanced java training center in bangalore
Thanks for sharing the awesome post.
ReplyDeleteAndroid App Development Company Malaysia
Today, the future is in the hands of cross-platform app frameworks. Cross-platform app development frameworks allow developers to create mobile applications that are compatible with more than one operating systems, in this case, iOS and Android. Here you find, what are the vital reasons you should learn 7 programming languages in 2020?
ReplyDeleteThanks for your post! Through your pen I found the problem up interesting! I believe there are many other people who are interested in them just like me! Thanks your shared!... I hope you will continue to have similar posts to share with everyone! I believe a lot of people will be surprised to read this article! DevOps online training in hyderabad
ReplyDeleteHello Admin!
ReplyDeleteThanks for the post. It was very interesting and meaningful. I really appreciate it! Keep updating stuffs like this. If you are looking for the Advertising Agency in Chennai | Printing in Chennai , Visit Inoventic Creative Agency Today..
Wow finally I got good article about android development process from beginning. Thanks for sharing
ReplyDeleteAndroid App Development Company Malaysia
Custom Software Development Company Malaysia
Software Development Company Malaysia
I have recently found an excellent Salesforce Training in India whose faculty is exceptional and you can also try this Salesforce Training and Certification in Jaipur whose syllabus is state of art. Here at Salesforce Training in Mumbai instructors are perfect to teach salesforce crm. My advice for you is to join demo at Salesforce training in Pune | Course Cost and in weekends try this best Salesforce Training in Noida | Course Cost who is providing great teaching services on Salesforce Training in Delhi and Fee Details.
ReplyDeleteI think you did an awesome allahabad university BA 3rd year result job explaining it. Sure beats having to research it allahabad university bsc 1st year Result on my own. Thanks
ReplyDeleteabinitio training
ReplyDeletespark training
scala training
azure devops training
app v training
sccm training
Nice read, I just passed this onto a friend who was doing a little research on that. Jungle Cruise Full Movie 2021
ReplyDeleteWriting this type of article is one of the most important things you will ever learn. This is the type of articleBuy tinder accounts you will use to build your reputation as an author and also one that will help you get started in a career that is very profitable. Many people will ask me what I consider to be the most important part of this type of article. The answer is simple, the title. You need to create a quality title for your article before submitting it for publication.Buy snapchat account
ReplyDeleteAgen Slot Online Terpercaya
ReplyDeleteAgen Slot Online Terpercaya
sap sd online training
ReplyDeletesap bw on hana online training
windows admin online training
app v online training
osb online training
oracle scm online training
I really like and appreciate your post.Really thank you! Fantastic.
ReplyDeleteVisit us: Core Java Online Training India
Visit us: Core java online training Hyderabad
Excellent blog and I really glad to visit your post. Keep continuing...
ReplyDeleteinternship meaning | internship meaning in tamil | internship work from home | internship certificate format | internship for students | internship letter | Internship completion certificate | internship program | internship certificate online | internship graphic design
If you’re a business owner looking for bulk PVA Accounts to boost your marketing efforts, the right agency can be a major asset. buypvaaccounts.xyz is the best bulk PVA Accounts provider agency in the market. Buy PVA Accounts with premium quality at an affordable price.
ReplyDeleteBuy PVA Accounts
Buy Gmail Accounts
Buy Facebook Accounts
Buy Instagram Accounts
Thanks a lot for sharing us about this update. Hope you will not get tired on making posts as informative as this.
ReplyDeleteBuy Gmail Accounts
Buy Email Account
Ios app development Bangalore
ReplyDeleteApprient is the most preferred iOS app Development Company in Bangalore. with hundreds of apps delivered across a wide range of business domains over.
Are you looking for the best Azure Training in Chennai? Here is the best suggestion for you, Infycle Technologies the best Software training institute in Chennai to study Azure platform with the top demanding courses such as Graphic Design and Animation, Cyber Security, Blockchain, Data Science, Oracle, AWS DevOps, Python, Big data, Python, Selenium Testing, Medical Coding, etc., with best offers. To know more about the offers, approach us on +91-7504633633, +91-7502633633
ReplyDeleteSnapchat is a well-known internet messaging application buy snapchat account available for Android and iOS devices. Not only can you share photographs and videos with your friends instantly, but you can also engage in a variety of activities with the verified snapchat account.
ReplyDelete