forked from wpilibsuite/frc-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add detail to Java Units documentation (wpilibsuite#2397)
* Add detail to Java Units documentation * Add Java GC * PR comments * Add section about Generics and the verbose syntax * Correct typo (still exists in Javadoc) * Remove object pooling * Fix heading structure * Consistent defined termininology for dimension, unit, and measure * More review comments * Last of the review comments * Add use of volts per meter per second
- Loading branch information
Showing
3 changed files
with
138 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ Basic Programming | |
using-test-mode | ||
reading-stacktraces | ||
functions-as-data | ||
java-gc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Java Garbage Collection | ||
======================= | ||
Java garbage collection is the process of automatically managing memory for Java objects. The Java Virtual Machine (JVM) is responsible for creating and destroying objects, and the garbage collector is responsible for identifying and reclaiming unused objects. | ||
|
||
Java garbage collection is an automatic process, which means that the programmer does not need to explicitly deallocate memory. The garbage collector keeps track of which objects are in use and which are not, and it periodically reclaims unused objects. | ||
|
||
Object Creation | ||
--------------- | ||
|
||
Creating a large number of objects in Java can lead to memory and performance issues. While the Java Garbage Collector (GC) is designed to handle memory management efficiently, creating too many objects can overwhelm the GC and cause performance degradation. | ||
|
||
Memory Concerns | ||
^^^^^^^^^^^^^^^ | ||
|
||
When a large number of objects are created, it increases the overall memory footprint of the application. While the overhead for a single object may be insignificant, it can become substantial when multiplied by a large number of objects. | ||
|
||
Performance Concerns | ||
^^^^^^^^^^^^^^^^^^^^ | ||
|
||
The GC's job is to periodically identify and reclaim unused objects in memory. While garbage collection is running on an FRC robot coded in Java, execution of the robot program is paused. When the GC has to collect a large number of objects, it has to pause the application to run more frequently or for longer periods of time. This is because the GC has to perform more work to collect and process each object. | ||
|
||
GC-related performance degradation in robot programs can manifest as occasional pauses, freezes, or loop overruns as the GC works to reclaim memory. | ||
|
||
Design Considerations | ||
^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
If you anticipate your application creating a large number of short-lived objects, it is important to consider design strategies to mitigate the potential memory and performance issues. Here are some strategies to consider: | ||
|
||
- Minimize object creation: Carefully evaluate the need for each object creation. If possible, reuse existing objects or use alternative data structures, such as arrays or primitives, to avoid creating new objects. | ||
|
||
- Efficient data structures: Use data structures that are well-suited for the type of data you are working with. For example, if you are dealing with a large number of primitive values, consider using arrays or collections specifically designed for primitives. |
Oops, something went wrong.