A method for collecting information, comprising: when a quantity of times of invoking a target method in a running lifecycle of a target program increases, obtaining, based on a method identifier of the target method, the quantity of times of invoking the target method, wherein the target program is any running program, and the target method is any one of at least one method invoked by the target program; and if the quantity of times of invoking the target method is greater than a first threshold, recording method information of the target method and setting a method status of the target method to a first state, if the quantity of times of invoking the target method is greater than a second threshold and not greater than the first threshold, recording the method information of the target method and setting the method status of the target method to the second state, wherein the first threshold and the second threshold are positive integers, and the second threshold is greater than 0 and less than the first threshold, wherein recording (S202, S204) the method information comprises writing the method information of the target method into a profile file corresponding to the target program; obtaining a start address and an end address of a hot method, wherein the hot method a method whose corresponding method information is written into the profile file and whose method status is the first state; obtaining a start address and an end address of a cold method based on the start address and the end address of the hot method, wherein the cold method is a method that is invoked by the target program, whose corresponding method information is not written into the profile file, or the cold method is a method that corresponds to the method information in the profile file and whose method status is the second state; releasing, based on the start address and the end address of the cold method, memory occupied by code of the cold method; and performing ahead-of-time, AOT, compilation on the method information of the hot method. when a quantity of times of invoking a target method in a running lifecycle of a target program increases, obtaining, based on a method identifier of the target method, the quantity of times of invoking the target method, wherein the target program is any running program, and the target method is any one of at least one method invoked by the target program; and if the quantity of times of invoking the target method is greater than a first threshold, recording method information of the target method and setting a method status of the target method to a first state, if the quantity of times of invoking the target method is greater than a second threshold and not greater than the first threshold, recording the method information of the target method and setting the method status of the target method to the second state, wherein the first threshold and the second threshold are positive integers, and the second threshold is greater than 0 and less than the first threshold, wherein recording (S202, S204) the method information comprises writing the method information of the target method into a profile file corresponding to the target program; obtaining a start address and an end address of a hot method, wherein the hot method a method whose corresponding method information is written into the profile file and whose method status is the first state; obtaining a start address and an end address of a cold method based on the start address and the end address of the hot method, wherein the cold method is a method that is invoked by the target program, whose corresponding method information is not written into the profile file, or the cold method is a method that corresponds to the method information in the profile file and whose method status is the second state; releasing, based on the start address and the end address of the cold method, memory occupied by code of the cold method; and performing ahead-of-time, AOT, compilation on the method information of the hot method.