Function 49h Free Allocated Memory

mov ax, SegmentMem ;segment address of memory to free

mov es, ax

mov ah, 49h ;Free Allocated Memory

int 21h

jc error_handler ;carry set means error

Free Allocated Memory (Function 49h) frees a block of memory previously allocated by Allocate Memory (Function 48h).

Parameter

SegmentMem

Specifies the segment address of the memory block to be freed. This address must have been returned from a call to the Allocate Memory function.

Return Value

If the function is successful, the carry flag is clear. Otherwise, the carry flag is set and the AX register contains an error value, which may be one of the following:

Value Name

0007h ERROR_ARENA_TRASHED
0009h ERROR_INVALID_BLOCK

Comment

MS-DOS returns 0009h (ERROR_INVALID_BLOCK) if a program tries to free memory that was not allocated by Allocate Memory.

See Also

Function 48h Allocate Memory