Last active
August 30, 2025 11:33
-
-
Save sunmeat/e5d2277b4a6337a5d467 to your computer and use it in GitHub Desktop.
finalize java example
This file contains hidden or 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
package com.alex.destructor; | |
class Person { | |
String name; | |
String surname; | |
int age; | |
Person() { // конструктор без параметрів | |
name = "Олександр"; | |
surname = "Загоруйко"; | |
age = 36; | |
} | |
Person(int number) { // конструктор з параметрами 1 | |
age = number; | |
} | |
Person(String n, String s, int a) { // конструктор з параметрами 2 | |
name = n; | |
surname = s; | |
age = a; | |
} | |
void print() { | |
System.out.println(name + " " + surname + ", " + age + " років."); | |
} | |
@Override | |
protected void finalize() throws Throwable { | |
super.finalize(); | |
System.out.println("Object # " + age); | |
} | |
} | |
class Program { | |
public static void main(String[] args) { | |
int count = 100000; | |
for (int i = 0; i < count; i++) { | |
Person p = new Person(i); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment