Message communication method, system, device, medium and product

By storing the correspondence between the instance object and the notification name in the application's memory, and freeing memory when the instance object is destroyed, the low memory utilization and memory leakage caused by instance object communication in the application is solved, and more efficient memory management is achieved.

CN120045324APending Publication Date: 2025-05-27BEIJING 58 INFORMATION TTECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510121019.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-25
Publication Date
2025-05-27

AI Technical Summary

Technical Problem

In the prior art, the application program leads to low memory utilization and memory leakage during message communication between instance objects.

Method used

By storing the correspondence between the instance object and the notification name in the application's memory, and calling the memory release method of the notification center class when the instance object is destroyed, the correspondence relationship will be automatically deleted, thereby freeing memory.

Benefits of technology

Improves the memory utilization of the application, reduces the possibility of memory leaks, and ensures effective memory management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120045324A_ABST
    Figure CN120045324A_ABST
Patent Text Reader

Abstract

Provided in an embodiment of the present invention are a message communication method, system, device, medium and product, the method comprising: in response to registration of an instance object in an application, allocating notification names in a first notification name set to the instance object, and storing a corresponding relationship between the instance object and the notification name allocated to the instance object into a memory of the application program. And then, in response to reception of a target message containing the target notification name, determining a target instance object corresponding to the target notification name, and sending the target message to the target instance object. And finally, in response to destruction of the target instance object, calling a memory release method to delete the corresponding relationship containing the target instance object. Visibly, the corresponding relation containing the destroyed target page instance object can be automatically deleted through the memory release method, the situation that the corresponding relation containing the destroyed target instance object occupies the memory of the application program is improved, and the memory utilization rate of the application program is increased.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a message communication method, system, device, medium and product. Background Art

[0002] In actual applications, an application includes multiple pages, and a page may include multiple instance objects. And the jump between pages can be achieved by means of communication between instance objects. Among them, the communication between instance objects can be achieved by relying on the message forwarding function provided by the notification center class. And the notification center class needs to use the application's memory when forwarding messages.

[0003] Based on the above description, how to improve the memory utilization of applications becomes a technical problem that needs to be solved urgently. Summary of the invention

[0004] In view of this, embodiments of the present invention provide a message communication method, system, device, medium and product to improve memory utilization of an application.

[0005] In a first aspect, an embodiment of the present invention provides a message communication method, including:

[0006] In response to registration of an instance object in an application, assigning a notification name in a first notification name set to the instance object;

[0007] Storing the correspondence between the instance object and the notification name assigned to the instance object in the memory of the application;

[0008] In response to receiving a target message including a target notification name, determining a target instance object corresponding to the target notification name;

[0009] Sending the target message to the target instance object;

[0010] In response to the destruction of the target instance object, a memory release method in the notification center class is called to delete the corresponding relationship including the target instance object from the memory of the application.

[0011] In a second aspect, an embodiment of the present invention provides a message communication system, the system is deployed in an application, the system includes a notification center class and a life cycle state management class;

[0012] The life cycle state management class is used to determine the life cycle state of the target instance object in the application program, so as to determine whether the target instance object is destroyed according to the life cycle state;

[0013] The notification center class is used to assign a notification name in the first notification name set to the instance object in response to the registration of the instance object; store the correspondence between the instance object and the notification name assigned to the instance object in the memory of the application; determine the target instance object corresponding to the target notification name in response to the receipt of a target message containing a target notification name; send the target message to the target instance object; if the target instance object is destroyed, then in response to the destruction of the target instance object, call a memory release method in the notification center class to delete the correspondence containing the target instance object from the memory of the application.

[0014] In a third aspect, an embodiment of the present invention provides a message communication device, including:

[0015] An allocation module, configured to allocate a notification name in a first notification name set to the instance object in response to registration of the instance object in the application;

[0016] A storage module, used for storing the correspondence between the instance object and the notification name assigned to the instance object in the memory of the application program;

[0017] A determination module, configured to determine a target instance object corresponding to the target notification name in response to receiving a target message including the target notification name;

[0018] A sending module, used for sending the target message to the target instance object;

[0019] The deletion module is used to call the memory release method in the notification center class in response to the destruction of the target instance object, so as to delete the corresponding relationship including the target instance object from the memory of the application.

[0020] In a fourth aspect, an embodiment of the present invention provides an electronic device, comprising a processor and a memory, wherein the memory is used to store one or more computer instructions, wherein the one or more computer instructions, when executed by the processor, implement the message communication method in the first aspect. The electronic device may also include a communication interface for communicating with other devices or communication systems.

[0021] In a fifth aspect, an embodiment of the present invention provides a non-temporary machine-readable storage medium having executable code stored thereon. When the executable code is executed by a processor of an electronic device, the processor can at least implement the message communication method as described in the first aspect above.

[0022] In a sixth aspect, an embodiment of the present invention provides a computer program product, which includes a computer program or instructions. When the computer program or instructions are executed by a processor, the processor is enabled to implement the message communication method as described in the first aspect above.

[0023] In the message communication method provided by an embodiment of the present invention, in response to the registration of an instance object in an application, the notification center class can assign a notification name in a first notification name set to the instance object. Then, the notification center class can store the correspondence between the instance object and the notification name assigned to the instance object in the memory of the application. Next, in response to the receipt of a target message containing a target notification name, the notification center class can determine the target instance object corresponding to the target notification name. Afterwards, the notification center class can send the target message to the target instance object. Finally, in response to the destruction of the target instance object, the notification center class can call a memory release method in the notification center class to delete the correspondence containing the target instance object from the memory of the application.

[0024] It can be seen that in the above scheme, the correspondence between the instance object and the notification name assigned to the instance object is stored in the memory of the application. Therefore, when the target instance object is destroyed, the notification center class can call the memory release method contained in itself to automatically delete the correspondence containing the target page instance object from the memory of the application, thereby improving the situation where the correspondence containing the target instance object that has been released occupies the application memory, that is, it can reduce the possibility of memory leaks, thereby improving the memory utilization of the application.

[0025] And because the notification names are centrally stored in the first notification name set, when the instance object is registered in the notification center class, the notification center class can quickly and accurately find the notification name that needs to be assigned to the instance object from the first notification name set. Further, based on the notification name, the notification center class can accurately send the target message to the target instance object. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0027] Figure 1 A flow chart of a message communication method provided by an embodiment of the present invention;

[0028] Figure 2A flowchart of another message communication method provided by an embodiment of the present invention;

[0029] Figure 3 A schematic diagram of the working process of a message communication method provided by an embodiment of the present invention;

[0030] Figure 4 A schematic diagram of the structure of a message communication system provided by an embodiment of the present invention;

[0031] Figure 5 A schematic diagram of the structure of a message communication device provided by an embodiment of the present invention;

[0032] Figure 6 For Figure 5 A schematic diagram of the structure of an electronic device corresponding to the message communication device provided in the illustrated embodiment. DETAILED DESCRIPTION

[0033] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0034] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "said" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings, and "multiple" generally includes at least two, but does not exclude the inclusion of at least one.

[0035] It should be understood that the term "and / or" used in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.

[0036] As used herein, the words "if" and "if" may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to identifying", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is identified" may be interpreted as "when determining" or "in response to determining" or "when identifying (stated condition or event)" or "in response to identifying (stated condition or event)", depending on the context.

[0037] It should be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a product or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such product or system. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the product or system including the elements.

[0038] It should also be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in the present invention are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0039] Some embodiments of the present invention are described in detail below in conjunction with the accompanying drawings. In the case where there is no conflict between the embodiments, the following embodiments and the features in the embodiments can be combined with each other. In addition, the step sequence in the following method embodiments is only an example and not a strict limitation.

[0040] Figure 1 The flowchart of a message communication method provided by an embodiment of the present invention. The message communication method provided by an embodiment of the present invention can be executed by a notification center class with a message forwarding function. Figure 1 As shown, the method comprises the following steps:

[0041] 101. In response to registration of an instance object in an application, assign a notification name in a first notification name set to the instance object.

[0042] 102, storing the correspondence between the instance object and the notification name assigned to the instance object in the memory of the application.

[0043] 103. In response to receiving a target message including a target notification name, determine a target instance object corresponding to the target notification name.

[0044] 104, sending the target message to the target instance object.

[0045] 105 . In response to the destruction of the target instance object, a memory release method in the notification center class is called to delete the corresponding relationship including the target instance object from the memory of the application.

[0046] The notification center class can, in response to the registration of the instance object in the application, assign the notification name in the first notification name set to the instance object. In other words, the notification center class can determine, based on the registration information of the instance object, which notification name the instance object is to receive, and the notification name is included in the first notification name set.

[0047] Optionally, the instance object in the application may include any one of a page instance object, a component instance object, and a data class instance object. Optionally, the first notification name set may be obtained in advance, which may specifically include multiple notification names added by the developer, and different notification names may be used to distinguish different types of messages. In actual applications, there are often multiple developers. In this case, the notification names added by different developers can be stored in the first notification name set to achieve unified management of notification names and avoid the problem of duplicate notification names.

[0048] Then, the notification center class can store the correspondence between the instance objects and the notification names assigned to the instance objects in the memory of the application. Optionally, the notification center class can create an array in advance and store the correspondence between the instance objects and the notification names assigned to the instance objects in the array, and the array is stored in the memory of the application.

[0049] In actual applications, the notification center class can provide a message forwarding function. Optionally, any instance object in the application can act as a message sender to send a target message containing a target notification name to the notification center class. The notification center class can respond to the reception of the target message containing the target notification name, determine the target instance object corresponding to the target notification name from the corresponding relationship stored in the memory, and forward the received target message to the target instance object. It can be understood that the target instance object is the message recipient, which can receive the target message forwarded by the notification center class.

[0050] Afterwards, the notification center class can obtain the life cycle state of the target instance object. If the life cycle state of the target instance object is in the destroyed state, indicating that the life cycle of the target instance object has ended and the target instance object has been destroyed, the notification center class can automatically call the memory release method in the notification center class in response to the destruction of the target instance object to delete the corresponding relationship including the target instance object from the application's memory, that is, to delete the corresponding relationship between the target instance object and the target notification name, so as to release the memory occupied by the destroyed target instance object in the application.

[0051] Optionally, the life cycle state of the target instance object may include a creation state, a start state, a resume state, a pause state, a stop state, and a destruction state, etc. Optionally, the memory release method may include a dealloc method in the notification center class.

[0052] In this embodiment, in response to the registration of an instance object in the application, the notification center class can assign a notification name in the first notification name set to the instance object. Then, the notification center class can store the correspondence between the instance object and the notification name assigned to the instance object in the memory of the application. Next, in response to the receipt of a target message containing a target notification name, the notification center class can determine the target instance object corresponding to the target notification name. Afterwards, the notification center class can send the target message to the target instance object. Finally, in response to the destruction of the target instance object, the notification center class can call a memory release method in the notification center class to delete the correspondence containing the target instance object from the memory of the application.

[0053] It can be seen that in the above scheme, the correspondence between the instance object and the notification name assigned to the instance object is stored in the memory of the application. Therefore, when the target instance object is destroyed, the notification center class can call the memory release method contained in itself to automatically delete the correspondence containing the target page instance object from the memory of the application, thereby improving the situation where the correspondence containing the target instance object that has been released occupies the application memory, that is, it can reduce the possibility of memory leaks, thereby improving the memory utilization of the application.

[0054] And because the notification names are centrally stored in the first notification name set, when the instance object is registered in the notification center class, the notification center class can quickly and accurately find the notification name that needs to be assigned to the instance object directly from the first notification name set. Further, based on the notification name, the notification center class can accurately send the target message to the target instance object.

[0055] According to the above description, in actual applications, the instance object in the application may include any one of a page instance object, a component instance object, and a data class instance object.

[0056] The registration process of a page instance object is described below by taking the example that the instance objects in an application program specifically include a page instance object.

[0057] Specifically, the notification center class can call the methods contained in it, such as the defaultCenter method, to register the page instance object, that is, to register the page instance object with the notification center class.

[0058] Optionally, in the process of registering the page instance object, the registration information generated may specifically include the message recipient for receiving messages, the method called during registration, the notification name contained in the message that the message recipient specified by the developer wants to receive, and the message sender specified by the developer, etc.

[0059] Further, after registering the page instance object with the notification center class, the notification center class may, in response to the registration of the page instance object in the application, assign a notification name in the first notification name set to the page instance object. Optionally, the page instance object may include at least one.

[0060] For example, assuming that the first page instance object and the second page instance object are registered with the notification center class, the notification center class can respond to the registration of the first page instance object by first determining the notification name, such as name1, contained in the message that the first page instance object wants to receive, contained in the registration information. Afterwards, the notification center class can assign name1 in the first notification name set to the first page instance object, that is, establish a corresponding relationship between name1 and the first page instance object.

[0061] Similarly, in response to the registration of the second page instance object, the notification center class can first determine the notification name contained in the message that the second page instance object wants to receive, such as name2, contained in the registration information. Afterwards, the notification center class can assign name2 in the first notification name set to the second page instance object, that is, establish a corresponding relationship between name2 and the second page instance object.

[0062] In actual applications, optionally, the same page instance object may specify multiple times that it wants to receive messages containing different notification names. For example, the first page instance object may specify that it wants to receive a message containing a notification name of name1, and thereafter, the first page instance object may further specify that it wants to receive a message containing a notification name of name3.

[0063] In addition, when the instance objects in the application specifically include component instance objects, the notification center class can also call the defaultCenter method contained in itself to register the component instance object. Similarly, when the instance objects in the application specifically include data class instance objects, the notification center class can also call the defaultCenter method contained in itself to register the data class instance object. The specific registration process can refer to the above description of the registration process of the page instance object, which will not be repeated here.

[0064] In this embodiment, different types of instance objects in the application can be registered by calling methods in the notification center class. And because the registration information generated by the registration includes the notification name contained in the message that each instance object wants to receive, the notification center class can accurately assign the corresponding notification name to each instance object after responding to the registration of the instance object, thereby ensuring the accuracy of subsequent message forwarding.

[0065] Figure 1 In the illustrated embodiment, it has been mentioned that the notification names in the first notification name set can be assigned to instance objects in the application.

[0066] For obtaining the first notification name set, optionally, the notification center class may first obtain a second notification name set including notification names of an enumeration type. Then, the notification center class may convert the notification names of the enumeration type into notification names of a string type to obtain the first notification name set. Afterwards, the notification center class may store the file including the first notification name set in the memory of the application.

[0067] Furthermore, the notification center class can directly obtain the first notification name set from the memory of the application, and assign the notification names in the first notification name set to the instance objects in the application.

[0068] The second notification name set may be pre-created by the developer. Specifically, the developer may directly add a field in the enumeration definition to store the notification name to obtain the second notification name set, thereby realizing centralized management of the notification names and avoiding duplication of notification names.

[0069] In actual applications, developers can also manually write string constants to add notification names. However, the same application is often developed by multiple developers. Therefore, if multiple developers add notification names together, duplicate notification names may occur, and notification names may be difficult to manage, which may cause the instance object that is the message receiver to be unable to correctly receive the message.

[0070] In this embodiment, compared to the method in which developers manually write string constants to add notification names, in this solution, the second notification name set contains enumerated type notification names, and each notification name obtained by enumeration is unique. Furthermore, the notification names contained in the first notification name set obtained by converting the second notification name set are also unique, which can obviously improve the problem of duplicate notification names, thereby ensuring that the subsequent notification center class can accurately assign the notification names in the first notification name set to instance objects.

[0071] In actual applications, when an instance object is created, the application can allocate a piece of memory to the instance object and return an address reference pointing to this memory. In other words, the address reference can point to the memory address allocated to the instance object.

[0072] Regarding the sending of the target message, specifically, the notification center class can call the method contained in itself, such as the defaultCenter method, to send the target message to the target instance object according to the address reference contained in the target message.

[0073] Taking into account the actual application scenarios, the target message sent by the notification center class can also include notification parameters for identifying the source of the notification and additional parameters related to the target notification name, so that the target instance object as the message recipient can use these parameters to execute specific functional logic, such as updating the user interface, processing data, etc.

[0074] In this embodiment, by calling the method in the notification center class, the target message is sent to the target instance object, which can decouple the message sender and the message receiver to enhance the interactive ability of the application. Before sending the target message, the notification center class can accurately send the target message to the target instance object according to the address reference contained in the target message. And because the sent target message also includes notification parameters for identifying the source of the notification and additional parameters related to the target notification name, the target instance object can better execute specific functional logic.

[0075] Figure 2 Flow chart of another message communication method provided by an embodiment of the present invention. Figure 2 As shown, the method may include the following steps:

[0076] 201. In response to registration of an instance object in an application, assign a notification name in a first notification name set to the instance object.

[0077] 202, storing the correspondence between the instance object and the notification name assigned to the instance object in the memory of the application.

[0078] 203. In response to receiving a target message including a target notification name, determine a target instance object corresponding to the target notification name.

[0079] 204, sending the target message to the target instance object.

[0080] 205, calling a method in the notification center class to create a notification center class instance object.

[0081] 206 , binding the notification center class instance object to the target instance object, so that the life cycle state of the notification center class instance object is the same as the life cycle state of the target instance object.

[0082] 207. If the target instance object is in a destroyed state, in response to the destruction of the target instance object, a memory release method in the notification center class is called to traverse the correspondence between the instance objects stored in the memory and the notification names assigned to the instance objects, and delete the correspondence including the target instance object.

[0083] The specific implementation process of the above steps 201 to 204 can be found in Figure 1 The specific description of the illustrated embodiments will not be repeated here.

[0084] The notification center class can call the methods contained in it, such as the defaultCenter method, to create a notification center class instance object. Then, the notification center class can bind the notification center class instance object to the target instance object so that the life cycle state of the notification center class instance object is the same as the life cycle state of the target instance object.

[0085] Specifically, developers can add notification properties to the notification center class so that the notification center class can bind the notification center class instance object to the target instance object based on the notification property, so that the life cycle state of the notification center class instance object is the same as the life cycle state of the target instance object.

[0086] Furthermore, when the life cycle state of the target instance object is in the destroyed state, indicating that the target instance object has been destroyed, the notification center class can automatically call the memory release method in the notification center class in response to the destruction of the target instance object, such as the dealloc method, to traverse the correspondence between the instance objects stored in the application's memory and the notification name assigned to the instance object, find and delete the correspondence including the target instance object, that is, delete the correspondence between the target instance object stored in the memory and the target notification name assigned to the target instance object.

[0087] In this embodiment, by binding the notification center class instance object with the target instance object, the life cycle state of the target instance object can be made the same as the life cycle state of the notification center class instance object, that is, the notification center class can perceive the life cycle state of the target instance object in real time. And when the life cycle state of the target instance object is in the destroyed state, the memory release method can be automatically called to delete the corresponding relationship containing the target instance object stored in the memory in time, thereby improving the memory utilization of the application.

[0088] For ease of understanding, you can combine Figure 3 The working process of the above-mentioned message communication method is explained by taking the message sending and receiving scenario as an example. Figure 3 As shown, it is assumed that the message sender includes the third page instance object and the message receiver includes the fourth page instance object.

[0089] Specifically, in response to the registration of the fourth page instance object, the notification center class may first assign the target notification name in the first notification name set to the fourth page instance object. Then, the notification center class may store the correspondence between the fourth instance object and the target notification name assigned to the fourth page instance object in the memory of the application.

[0090] In actual applications, the third page instance object can send a target message containing a target notification name to the notification center class. The notification center class can determine the fourth page instance object corresponding to the target notification name in response to receiving the target message containing the target notification name. Afterwards, the notification center class can call the method contained in itself to send the target message to the target instance object according to the address reference contained in the target message.

[0091] That is to say, after receiving the target message containing the target notification name, the notification center class can determine the fourth page instance object that has been pre-registered and wants to receive this target message, and apply the target message correctly to the fourth page instance object according to the address contained in the target message.

[0092] Afterwards, if the life cycle state of the fourth page instance object is in the destroyed state, indicating that the life cycle of the fourth page instance object has ended, the notification center class can respond to the destruction of the fourth page instance object and automatically call the memory release method contained in itself to delete the correspondence including the fourth page instance object from the memory of the application, that is, delete the correspondence between the fourth page instance object and the target notification name, and release the memory occupied by the destroyed fourth page instance object in the application, thereby improving the memory utilization of the application.

[0093] In addition, for the contents not described in detail in this embodiment, reference can be made to the relevant descriptions in the above embodiments, and they will not be repeated here.

[0094] To facilitate understanding, the message communication methods provided in the above embodiments may also be described from the perspective of the entire system. Figure 4 A structural diagram of a message communication system provided by an embodiment of the present invention, such as Figure 4 As shown, the message communication system can be deployed in an application. The message communication system can specifically include a notification center class and a life cycle state management class.

[0095] The notification center class may, in response to the registration of the instance object, assign a notification name in the first notification name set to the instance object. Optionally, the instance object in the application may include any one of a page instance object, a component instance object, and a data class instance object. Optionally, the first notification name set may be obtained in advance, and may specifically include multiple notification names added by the developer, and different notification names may be used to distinguish different types of messages.

[0096] Then, the notification center class can store the correspondence between the instance object and the notification name assigned to the instance object in the memory of the application. Then, in response to receiving a target message including the target notification name, the notification center class can determine the target instance object corresponding to the target notification name and send the target message to the target instance object.

[0097] The life cycle state management class can determine the life cycle state of the target instance object in the application to determine whether the target instance object is destroyed according to the life cycle state of the target instance object. Optionally, the life cycle state management class can use a hook function to monitor the life cycle state of the target instance object in the application.

[0098] Optionally, the life cycle state may include a creation state, a start state, a resume state, a pause state, a stop state, and a destruction state, etc. When the life cycle state of the target instance object is in a destruction state, that is, when the life cycle of the target instance object ends, the life cycle state management class may determine that the target instance object is destroyed.

[0099] Afterwards, if it is determined through the lifecycle state management class that the target instance object is destroyed, the notification center class can respond to the destruction of the target instance object by calling the memory release method in the notification center class, such as the dealloc method, to delete the corresponding relationship including the target instance object from the application's memory, that is, to delete the corresponding relationship between the target instance object and the target notification name, thereby releasing the memory occupied by the destroyed target instance object in the application.

[0100] In this embodiment, the message communication system deployed in the application includes a notification center class and a life cycle state management class. The notification center class can assign a notification name in the first notification name set to the instance object in response to the registration of the instance object in the application. Then, the notification center class can store the correspondence between the instance object and the notification name assigned to the instance object in the memory of the application. Next, the notification center class can determine the target instance object corresponding to the target notification name in response to the reception of the target message containing the target notification name, and send the target message to the target instance object. Afterwards, the life cycle state management class can determine the life cycle state of the target instance object in the application to determine whether the target instance object is destroyed based on the life cycle state. If the life cycle state management class determines that the target instance object is destroyed, the notification center class can call a memory release method in response to the destruction of the target instance object to delete the correspondence containing the target instance object from the memory of the application.

[0101] It can be seen that in the above scheme, the correspondence between the instance object and the notification name assigned to the instance object is stored in the memory of the application. Therefore, when it is determined through the life cycle state management class that the target instance object is destroyed, the notification center class can call the memory release method contained in itself to automatically delete the correspondence containing the target page instance object from the memory of the application, thereby improving the situation in which the correspondence containing the target instance object that has been released occupies the application memory, that is, it can reduce the possibility of memory leaks, thereby improving the memory utilization of the application.

[0102] And because the notification names are centrally stored in the first notification name set, when the instance object is registered in the notification center class, the notification center class can quickly and accurately find the notification name that needs to be assigned to the instance object directly from the first notification name set. Further, based on the notification name, the notification center class can accurately send the target message to the target instance object.

[0103] Figure 4 In the illustrated embodiment, it has been mentioned that the notification names in the first notification name set can be assigned to instance objects in the application.

[0104] For obtaining the first notification name set, optionally, the notification center class may first obtain a second notification name set including notification names of an enumeration type. Then, the notification center class may convert the notification names of the enumeration type into notification names of a string type to obtain the first notification name set.

[0105] Afterwards, the notification center class can store the file containing the first notification name set in the memory of the application. Further, the notification center class can directly obtain the first notification name set from the memory of the application and assign the notification names in the first notification name set to instance objects in the application.

[0106] The second notification name set may be pre-created by the developer. Specifically, the developer may directly add a field in the enumeration definition to store the notification name to obtain the second notification name set, thereby realizing centralized management of the notification names and avoiding duplication of notification names.

[0107] In this embodiment, compared to the method in which the developer manually writes a string constant to add notification names, in this solution, the second notification name set contains enumerated type notification names, and each notification name obtained by enumeration is unique. Furthermore, the notification names contained in the first notification name set obtained by converting the second notification name set are also unique, which can obviously improve the problem of duplicate notification names, thereby ensuring that the subsequent notification center class can accurately assign the notification names in the first notification name set to instance objects.

[0108] The message communication device of one or more embodiments of the present invention will be described in detail below. Those skilled in the art will appreciate that these message communication devices can be configured using commercially available hardware components through the steps taught in this solution.

[0109] Figure 5 A schematic diagram of the structure of a message communication device provided by an embodiment of the present invention, such as Figure 5 As shown, the device comprises:

[0110] The allocation module 11 is used for allocating notification names in the first notification name set to the instance object in response to registration of the instance object in the application.

[0111] The storage module 12 is used to store the corresponding relationship between the instance object and the notification name assigned to the instance object in the memory of the application.

[0112] The determination module 13 is used to determine the target instance object corresponding to the target notification name in response to receiving the target message including the target notification name.

[0113] The sending module 14 is used to send the target message to the target instance object.

[0114] The deleting module 15 is used to call the memory release method in the notification center class in response to the destruction of the target instance object, so as to delete the corresponding relationship including the target instance object from the memory of the application.

[0115] Optionally, the instance object includes a page instance object. Based on this, the device also includes a registration module 16 for calling a method in the notification center class to register the page instance object in the application, and the page instance object includes at least one.

[0116] Optionally, the sending module 14 is used to call a method in the notification center class to send the target message to the target instance object according to the address reference included in the target message.

[0117] Optionally, the device further includes a type conversion module 17, which is used to obtain a second notification name set including notification names of enumerated type; and convert the notification names of the enumerated type into notification names of string type to obtain the first notification name set.

[0118] The storage module 12 is used to store the file containing the first notification name set in the memory of the application.

[0119] Optionally, the deletion module 15 is used to call the method in the notification center class to create a notification center class instance object; bind the notification center class instance object to the target instance object so that the life cycle state of the notification center class instance object is the same as the life cycle state of the target instance object; if the target instance object is in a destroyed state, then in response to the destruction of the target instance object, call the memory release method in the notification center class to traverse the correspondence between the instance object stored in the memory and the notification name assigned to the instance object, and delete the correspondence including the target instance object.

[0120] Figure 5 The device shown can perform Figures 1 to 3 For the method of the embodiment shown in the figure, the part not described in detail in this embodiment can be referred to Figures 1 to 3 The implementation process and technical effects of this technical solution refer to Figures 1 to 3 The description in the illustrated embodiment will not be repeated here.

[0121] In a possible design, the structure of the message communication device can be implemented as an electronic device, such as Figure 6 As shown, the electronic device may include: a processor 21 and a memory 22. The memory 22 is used to store the electronic device to perform the above Figures 1 to 3The program of the message communication method provided in the illustrated embodiment, the processor 21 is configured to execute the program stored in the memory 22.

[0122] The program includes one or more computer instructions, wherein the one or more computer instructions can implement the following steps when executed by the processor 21:

[0123] In response to registration of an instance object in an application, assigning a notification name in a first notification name set to the instance object;

[0124] Storing the correspondence between the instance object and the notification name assigned to the instance object in the memory of the application;

[0125] In response to receiving a target message including a target notification name, determining a target instance object corresponding to the target notification name;

[0126] Sending the target message to the target instance object;

[0127] In response to the destruction of the target instance object, a memory release method in the notification center class is called to delete the corresponding relationship including the target instance object from the memory of the application.

[0128] Optionally, the processor 21 is further configured to execute the aforementioned Figures 1 to 3 All or part of the steps in the illustrated embodiments.

[0129] The structure of the electronic device may further include a communication interface 23 for the electronic device to communicate with other devices or a communication network.

[0130] In addition, an embodiment of the present invention provides a non-transitory machine-readable storage medium for storing computer software instructions used by the above electronic device, which includes instructions for executing the above Figure 1 to Figure 3 The procedures involved in the message communication method shown.

[0131] In addition, an embodiment of the present invention provides a computer program product. The computer program product includes a computer program or an instruction. When the computer program or the instruction is executed by a processor, the processor is enabled to implement the above Figure 1 to Figure 3 The steps or functions of the message communication method shown.

[0132] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A message communication method, characterized in that: Applicable to the notification center class, including: In response to registration of an instance object in an application, assigning a notification name in a first notification name set to the instance object; Storing the correspondence between the instance object and the notification name assigned to the instance object in the memory of the application; In response to receiving a target message including a target notification name, determining a target instance object corresponding to the target notification name; Sending the target message to the target instance object; In response to the destruction of the target instance object, a memory release method in the notification center class is called to delete the corresponding relationship including the target instance object from the memory of the application.

2. The method according to claim 1, characterized in that The instance object includes a page instance object, and the method further includes: The method in the notification center class is called to register the page instance object in the application, wherein the page instance object includes at least one.

3. The method according to claim 1, characterized in that: The sending the target message to the target instance object includes: The method in the notification center class is called to send the target message to the target instance object according to the address reference contained in the target message.

4. The method according to claim 1, characterized in that: The method further comprises: Get the second notification name set containing notification names of enumeration type; Convert the notification name of the enumeration type into a notification name of a string type to obtain the first notification name set; A file containing the first set of notification names is stored in a memory of the application.

5. The method according to claim 1, characterized in that In response to the destruction of the target instance object, calling a memory release method in the notification center class to delete the corresponding relationship including the target instance object from the memory of the application program includes: Calling a method in the notification center class to create a notification center class instance object; Binding the notification center class instance object to the target instance object so that the life cycle state of the notification center class instance object is the same as the life cycle state of the target instance object; If the target instance object is in a destroyed state, in response to the destruction of the target instance object, the memory release method in the notification center class is called to traverse the correspondence between the instance object stored in the memory and the notification name assigned to the instance object, and delete the correspondence including the target instance object.

6. A message communication system, characterized in that: The system is deployed in an application, and includes: a notification center class and a life cycle state management class; The life cycle state management class is used to determine the life cycle state of the target instance object in the application program, so as to determine whether the target instance object is destroyed according to the life cycle state; The notification center class is used to assign a notification name in a first notification name set to the instance object in response to the registration of the instance object; store the correspondence between the instance object and the notification name assigned to the instance object in the memory of the application; determine the target instance object corresponding to the target notification name in response to the receipt of a target message containing a target notification name; send the target message to the target instance object; if the target instance object is destroyed, then in response to the destruction of the target instance object, call a memory release method in the notification center class to delete the correspondence containing the target instance object from the memory of the application.

7. The system according to claim 6, characterized in that The notification center class is used to obtain a second notification name set containing an enumeration type notification name; convert the enumeration type notification name into a string type notification name to obtain the first notification name set; and store the file containing the first notification name set in the memory of the application.

8. An electronic device, characterized in that: include: A memory and a processor; wherein the memory stores executable code, and when the executable code is executed by the processor, the processor executes the message communication method according to any one of claims 1 to 5.

9. A non-transitory machine-readable storage medium, characterized in that: The non-transitory machine-readable storage medium stores executable code, and when the executable code is executed by a processor of an electronic device, the processor is caused to execute the message communication method according to any one of claims 1 to 5.

10. A computer program product, characterized in that The computer program product includes a computer program or instructions, so that the computer program or instructions can implement the steps in the message communication method according to any one of claims 1 to 5.