Home / Class/ ResourceLeakDetector Class — netty Architecture

ResourceLeakDetector Class — netty Architecture

Architecture documentation for the ResourceLeakDetector class in ResourceLeakDetector.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  f4ad5acd_fee3_2377_9c2f_bc298798ad25["ResourceLeakDetector"]
  d32ce738_76fd_52e1_72e6_97f959369f2a["ResourceLeakDetector.java"]
  f4ad5acd_fee3_2377_9c2f_bc298798ad25 -->|defined in| d32ce738_76fd_52e1_72e6_97f959369f2a
  f852baf9_850d_d44b_3197_a9869e13fc7d["setEnabled()"]
  f4ad5acd_fee3_2377_9c2f_bc298798ad25 -->|method| f852baf9_850d_d44b_3197_a9869e13fc7d
  172fa0e0_4063_857b_715a_811ce60228bb["isEnabled()"]
  f4ad5acd_fee3_2377_9c2f_bc298798ad25 -->|method| 172fa0e0_4063_857b_715a_811ce60228bb
  5b0af8ca_5190_33cc_31b6_4515c8bf019e["setLevel()"]
  f4ad5acd_fee3_2377_9c2f_bc298798ad25 -->|method| 5b0af8ca_5190_33cc_31b6_4515c8bf019e
  5d2be877_acc3_9d09_4f45_291beb3b69d7["Level()"]
  f4ad5acd_fee3_2377_9c2f_bc298798ad25 -->|method| 5d2be877_acc3_9d09_4f45_291beb3b69d7
  d0dc3523_62e5_2691_bc08_5c810a490564["ResourceLeakDetector()"]
  f4ad5acd_fee3_2377_9c2f_bc298798ad25 -->|method| d0dc3523_62e5_2691_bc08_5c810a490564
  4a8647c7_44d2_9333_c91b_685f22e86339["ResourceLeak()"]
  f4ad5acd_fee3_2377_9c2f_bc298798ad25 -->|method| 4a8647c7_44d2_9333_c91b_685f22e86339
  2716db04_fb06_578d_8d92_e54e2c543427["track()"]
  f4ad5acd_fee3_2377_9c2f_bc298798ad25 -->|method| 2716db04_fb06_578d_8d92_e54e2c543427
  f46017ba_a88b_6b0e_41c2_c3cbb8d0c4c6["trackForcibly()"]
  f4ad5acd_fee3_2377_9c2f_bc298798ad25 -->|method| f46017ba_a88b_6b0e_41c2_c3cbb8d0c4c6
  d770091a_121f_57a2_9e24_8ab20dbf8134["isRecordEnabled()"]
  f4ad5acd_fee3_2377_9c2f_bc298798ad25 -->|method| d770091a_121f_57a2_9e24_8ab20dbf8134
  6c6ec55a_3aba_b916_b994_11cf7c27c631["track0()"]
  f4ad5acd_fee3_2377_9c2f_bc298798ad25 -->|method| 6c6ec55a_3aba_b916_b994_11cf7c27c631
  e96112df_51ca_7e3f_05c2_3a8b99f89a09["clearRefQueue()"]
  f4ad5acd_fee3_2377_9c2f_bc298798ad25 -->|method| e96112df_51ca_7e3f_05c2_3a8b99f89a09
  82cad144_74fd_b0ed_11b2_7980d2760619["needReport()"]
  f4ad5acd_fee3_2377_9c2f_bc298798ad25 -->|method| 82cad144_74fd_b0ed_11b2_7980d2760619
  c749ac7c_d251_baf5_8030_89fe234647d9["reportLeak()"]
  f4ad5acd_fee3_2377_9c2f_bc298798ad25 -->|method| c749ac7c_d251_baf5_8030_89fe234647d9

Relationship Graph

Source Code

common/src/main/java/io/netty/util/ResourceLeakDetector.java lines 42–739

public class ResourceLeakDetector<T> {

    private static final String PROP_LEVEL_OLD = "io.netty.leakDetectionLevel";
    private static final String PROP_LEVEL = "io.netty.leakDetection.level";
    private static final Level DEFAULT_LEVEL = Level.SIMPLE;

    private static final String PROP_TARGET_RECORDS = "io.netty.leakDetection.targetRecords";
    private static final int DEFAULT_TARGET_RECORDS = 4;

    private static final String PROP_SAMPLING_INTERVAL = "io.netty.leakDetection.samplingInterval";
    // There is a minor performance benefit in TLR if this is a power of 2.
    private static final int DEFAULT_SAMPLING_INTERVAL = 128;

    private static final String PROP_TRACK_CLOSE = "io.netty.leakDetection.trackClose";
    private static final boolean DEFAULT_TRACK_CLOSE = true;

    private static final int TARGET_RECORDS;
    static final int SAMPLING_INTERVAL;
    private static final boolean TRACK_CLOSE;

    /**
     * Represents the level of resource leak detection.
     */
    public enum Level {
        /**
         * Disables resource leak detection.
         */
        DISABLED,
        /**
         * Enables simplistic sampling resource leak detection which reports there is a leak or not,
         * at the cost of small overhead (default).
         */
        SIMPLE,
        /**
         * Enables advanced sampling resource leak detection which reports where the leaked object was accessed
         * recently at the cost of high overhead.
         */
        ADVANCED,
        /**
         * Enables paranoid resource leak detection which reports where the leaked object was accessed recently,
         * at the cost of the highest possible overhead (for testing purposes only).
         */
        PARANOID;

        /**
         * Returns level based on string value. Accepts also string that represents ordinal number of enum.
         *
         * @param levelStr - level string : DISABLED, SIMPLE, ADVANCED, PARANOID. Ignores case.
         * @return corresponding level or SIMPLE level in case of no match.
         */
        static Level parseLevel(String levelStr) {
            String trimmedLevelStr = levelStr.trim();
            for (Level l : values()) {
                if (trimmedLevelStr.equalsIgnoreCase(l.name()) || trimmedLevelStr.equals(String.valueOf(l.ordinal()))) {
                    return l;
                }
            }
            return DEFAULT_LEVEL;
        }
    }

    private static Level level;

    private static final InternalLogger logger = InternalLoggerFactory.getInstance(ResourceLeakDetector.class);

    static {
        final boolean disabled;
        if (SystemPropertyUtil.get("io.netty.noResourceLeakDetection") != null) {
            disabled = SystemPropertyUtil.getBoolean("io.netty.noResourceLeakDetection", false);
            logger.debug("-Dio.netty.noResourceLeakDetection: {}", disabled);
            logger.warn(
                    "-Dio.netty.noResourceLeakDetection is deprecated. Use '-D{}={}' instead.",
                    PROP_LEVEL, Level.DISABLED.name().toLowerCase());
        } else {
            disabled = false;
        }

        Level defaultLevel = disabled? Level.DISABLED : DEFAULT_LEVEL;

        // First read old property name
        String levelStr = SystemPropertyUtil.get(PROP_LEVEL_OLD, defaultLevel.name());

Frequently Asked Questions

What is the ResourceLeakDetector class?
ResourceLeakDetector is a class in the netty codebase, defined in common/src/main/java/io/netty/util/ResourceLeakDetector.java.
Where is ResourceLeakDetector defined?
ResourceLeakDetector is defined in common/src/main/java/io/netty/util/ResourceLeakDetector.java at line 42.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free